我切换了一个商店内容管理系统,并把很多旧网址放入.htaccess,将旧产品重定向到它们的新位置。
但是一些重定向是错误的:
RedirectMatch 301 ^/products/catxy/313? https://www.example.com/products/catxy/product-1/
RedirectMatch 301 ^/products/catxy/314? https://www.example.com/products/catxy/product-2/
RedirectMatch 301 ^/products/catxy/319? https://www.example.com/products/catxy/product-3/当我转到example.com/products/catxy/319时,我被重定向到product-1,而不是product-3
根据我对上面的正则表达式的理解,它意味着以/products/catxy/319MAYBEMORE ->重定向到产品-3
我不能写^/products/catxy/ 319 $,因为319有很多不同的结尾(该产品id的所有变体)。
我也不知道在我的情况下使用mod_rewrite是不是更好。
发布于 2017-08-04 17:54:57
问题是在pattern:^/products/catxy/313?的末尾出现了?,它使最后一个数字成为可选的,因此您的第一个规则匹配任何以以下开头的规则:
/products/catxy/313或
products/catxy/31你的意思可能是保持尾部斜杠是可选的,并让你的规则像这样:
RedirectMatch 301 ^/products/catxy/313(?:/.*)?$ https://www.example.com/products/catxy/product-1/
RedirectMatch 301 ^/products/catxy/314(?:/.*)?$ https://www.example.com/products/catxy/product-2/
RedirectMatch 301 ^/products/catxy/319(?:/.*)?$ https://www.example.com/products/catxy/product-3/请记住,在测试更改之前要清除浏览器缓存。
https://stackoverflow.com/questions/45501948
复制相似问题