htaccess类别链接优化到主站点

时间:2014-11-07 06:29:51

标签: php regex .htaccess mod-rewrite redirect

我有htaccess文件,类别链接重定向到主站点

查看下面的代码

RewriteCond %{REQUEST_URI} ^/shop/test1(/)?$
RewriteRule (.*) http://example.com/test1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/shop/test2(/)?$
RewriteRule (.*) http://example.com/test2 [R=301,L]

RewriteCond %{REQUEST_URI} ^/shop/test3(/)?$
RewriteRule (.*) http://example.com/test3 [R=301,L]

优化上述代码的任何其他方法

1 个答案:

答案 0 :(得分:0)

这3条规则可以合并为单一规则

RewriteEngine On

RewriteRule ^shop/(test1|test2|test3)/?$ http://example.com/$1 [R=301,L,NC]