.htaccess重定向链接少于4个斜杠

时间:2014-12-10 11:23:49

标签: regex apache .htaccess mod-rewrite redirect

我对正则表达式没有任何问题,但我不知道如何编写.htaccess规则,我是否可以了解如何在给定规则上重定向页面:

OK  /page/product/type/id
301 /page/product/type         => /otherPage/product/type
301 /page/product              => /otherPage/product
301 /page                      => /otherPage
301 /otherPage/product/type/id => /page/product/type/id

1 个答案:

答案 0 :(得分:1)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On

RewriteRule ^page/([^/]+/[^/]+/?)$ /otherPage/$1 [L,NC,R=302]

RewriteRule ^page/([^/]+/?)$ /otherPage/$1 [L,NC,R=302]

RewriteRule ^page/?$ /otherPage [L,NC,R=302]

RewriteRule ^otherPage/([^/]+/[^/]+/[^/]+/?)$ /page/$1 [L,NC,R=302]