如何使用的.htaccess忽略/删除/页/ X /从网址是什么?如何使用、网址、htaccess

2023-09-02 10:10:23 作者:不爱,请闪开

我如何使用的.htaccess脱光/忽略/页/ X / X是页码,从我的网址,只有当它的domain.com之后,像domain.com/page/29/

刮板网站链接到我的网站分页上的帖子出于某种原因,导致谷歌抓取这些链接。不幸的是我的网站没有呈现出404,而是呈现出一个页面,规范网址是包括/页/ 29 /例如。这不好。伤害我的排名。

如何在htaccess的这样做,所以什么都像后分页/页名/仍能正常工作?

解决方案

您可以试试下面的规则,如果你想重写/页/ X /到/页/完全吻合。 (其中X是任何数目)

 重写规则^页/([0-9] +)/ $ http://domain.com/page/ [R = 302,L]
 

如果你想重写/ [anystring] / X /到/ [anystring] /你可以试试

 重写规则^(。*)/([0-9] +)/ $ http://domain.com/$1/ [R = 302,L]
 
甲由科技 响应式网站建设提升用户体验的 四不原则

How can I use .htaccess to strip/ignore /page/X/ where X is the page number, from my urls, ONLY if it's right after the domain.com, like domain.com/page/29/ ?

Scraper sites are linking to my site with pagination on posts for some reason, causing Google to crawl those links. Unfortunately my site is not showing a 404, but instead showing a page, and the canonical url is including /page/29/ for example. It's not good. Hurting my rankings.

How would this be done in htaccess, so that pagination after anything else like a /page-name/ would still work?

解决方案

You can try the following rule if you want to rewrite /page/X/ to /page/ exactly. (where X is any number)

RewriteRule ^page/([0-9]+)/$ http://domain.com/page/ [R=302,L]

If you want to rewrite /[anystring]/X/ to /[anystring]/ you can try

RewriteRule ^(.*)/([0-9]+)/$ http://domain.com/$1/ [R=302,L]