简体   繁体   English

如何使用.htaccess从网址中忽略/删除/ page / X /?

[英]How to use .htaccess to ignore/remove /page/X/ from url?

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/ ? 我如何才能使用.htaccess从我的网址中删除/忽略/ page / X /(其中X是页码),仅当它位于domain.com之后,例如domain.com/page/29/时?

Scraper sites are linking to my site with pagination on posts for some reason, causing Google to crawl those links. 出于某些原因,Scraper网站通过分页链接链接到我的网站,导致Google抓取了这些链接。 Unfortunately my site is not showing a 404, but instead showing a page, and the canonical url is including /page/29/ for example. 不幸的是,我的网站没有显示404,而是显示了一个页面,例如,规范的URL包括/ page / 29 /。 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? 如何在htaccess中完成此操作,以便在/ page-name /之类的其他分页仍然有效?

You can try the following rule if you want to rewrite /page/X/ to /page/ exactly. 如果要将/ page / X /准确地重写为/ page /,可以尝试以下规则。 (where X is any number) (其中X是任何数字)

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

If you want to rewrite /[anystring]/X/ to /[anystring]/ you can try 如果要将/ [anystring] / X /重写为/ [anystring] /,可以尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM