我有从旧站点到新构建的设置重定向。例如:
RedirectMatch 301 /articles/(.*) http://domain.com/articles/entry/$1
这很好,直到我访问domain.com/articles/entry/page-title url,并重复了/entry段。
即domain.com/articles/entry/entry/entry_entry/entry.entry/entry-entry/entry/entry/entry/entry/entry/ntry/entry/entry/entry/enntry/entry_ntry/entry-entery/entry/enry/entry/emtry/entry/entry/entry/page-title
有没有一种方法可以设置旧url的重定向,以重定向到新url,而不添加额外的/条目段?
您必须在正则表达式中使用锚点,以确保仅在开始时匹配/articles
,并使用负先行来停止重定向循环:
RedirectMatch 301 ^/articles/(?!(?:entry/|P'd))(.*)$ http://domain.com/articles/entry/$1
请确保在测试此更改之前清除浏览器缓存。