.htaccess不应该重定向

时间:2013-11-21 21:54:56

标签: regex apache .htaccess mod-rewrite

我今天修改了我的.htaccess文件的一些重写规则,如下所示:

RewriteRule ^about-us.php(.*)$ /about$1 [R=302,NC,L]
RewriteRule ^contact-us.php(.*)$ /service$1 [R=302,NC,L]
RewriteRule ^countertop-electrics/blenders(.*)$ /beverages/blenders [R=302,NC,L]

RewriteRule ^about-us.php(.*)$ /about [R=302,NC,L]
RewriteRule ^contact-us.php(.*)$ /service [R=302,NC,L]
RewriteRule ^countertop-electrics/blenders(.*)$ /beverages/blenders [R=302,NC,L]

目标是将产品页面(例如“countertop-electrics / blenders / product1234.html”)重定向到简单的类别页面,例如“饮料/搅拌机”,因为产品和类别的排序方式发生了变化。我通过降低$ 1或$来做到这一点,但现在似乎没有RewriteRules正在工作。我怎么能做到这一点?谢谢。

1 个答案:

答案 0 :(得分:1)

在正则表达式中使用.+

RewriteRule ^about-us\.php.*$ /about [R=302,NC,L]
RewriteRule ^contact-us\.php.*$ /service [R=302,NC,L]
RewriteRule ^countertop-electrics/blenders.+$ /beverages/blenders [R=302,NC,L]

QUERY_STRING将转移到新的URI。