我需要编写一个重写规则的代码,以便文章来自:
www.olddomain.com/categoryA/categoryB/article.html
被重定向到:
www.newdomain.com/categoryC/categoryD/article.html
所以这里的挑战是 article.html 页面不会从一个站点更改到另一个站点,但中间路径(类别)不同。
我试过编码这个规则:
RewriteRule ^(categoryA/categoryB/.+)$ http://www.newdomain.com/categoryC/categoryD/$1 [L,NC,R=301,NE]
但是,规则重定向自:
http://www.olddomain.com/categoryA/categoryB/article.html
到
http://www.newdomain.com/categoryC/categoryD/categoryA/categoryB/article.html
您能建议我在执行重定向时排除“旧”类别的方法吗?我希望被重定向到:
http://www.newdomain.com/categoryC/categoryD/article.html
非常感谢
最佳答案
就这么简单:
RewriteRule ^categoryA/categoryB/([^/]+)\.html$ http://www.newdomain.com/categoryC/categoryD/$1.html [R=301,L,NC,NE]
关于mod-rewrite - 重写中间路径的重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61367472/