我对正则表达式没有任何问题,但我不知道如何编写.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
答案 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]