0

I just discovered that I have some duplicate pages that I need to remove but some pages that should not exist are indexed and generating small amounts of traffic. I want to redirect those urls to the original ones.

http://www.example.com/buy-something.php

to

http://www.example.com/something.php

I basically need to remove the "buy-" in the urls and make sure the page is redirected to the proper page. Here is what I have so far:

#301 Redirect buy- to none
RewriteRule ^([a-zA-Z\.]+).php$  /buy-$1.php  [L,R=301]

But this does nothing to the pages that should be redirected and adds a loop of buy-buy-buy-buy-buy-buy- to other pages and causes them to time out. I have tried a few other variations but to no prevail.

Your help is greatly appreciated.

4

2 回答 2

1

您的重写规则不正确。它与您的意图相反。尝试这个:

#301 Redirect buy- to none
RewriteRule ^buy-(.*).php$  /$1.php  [L,R=301]
于 2013-08-07T13:32:16.017 回答
1

您混淆了语法,现在您将任何.php 重定向到 /buy-.php,因为您希望它以相反的方式尝试:

RedirectRule ^buy-([a-zA-Z\.]+).php$  /$1.php  [L,R=301]

这应该采用任何 buy-*.php 域并将它们重定向到带有代码 301 的 *.php。

来源: http ://httpd.apache.org/docs/current/mod/mod_rewrite.html

于 2013-08-07T13:32:55.067 回答