我需要以下页面的重写规则:
/blog/2015/09/05/name-of-page.html
/old-category-name/name-of-page/
/old-category-name/name-of-page
所有需要重定向到/ new-category-name / name-of-page /
但是,也可能有文件名,例如 / old-category-name / name-of-page-two将重定向到/ new-category-name / name-of-page-two /
我想出了以下正则表达式:
(\blog\/\[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/|old-category-name)\/\/name-of-file(\.html|\.htm|\/|\s)
它在Regex Pal中工作,但以下重定向在我的htaccess文件中不起作用:
Rewrite Rule (\blog\/\[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/|old-category-name)\/\/name-of-file(\.html|\.htm|\/|\s) http://example.com/new-category-name/name-of-file/
有人能给我一些建议吗?谢谢!
答案 0 :(得分:0)
您需要修复正则表达式和整体语法:
RewriteEngine On
RewriteRule ^(?:blog/\d{4}/\d{2}/\d{4}|old-category-name)/(name-of-page)(?:\.html|/)?$ /new-category-name/$1/ [L,NC,R=301]