0
try_files $uri/index.html $uri @moved;
  location @moved {
  rewrite ^/categories/dogs-c-food/products/xyz-product$ /categories/dogs/food/products/xyz-product permanent;
  rewrite ^/categories/dogs-c-leash/products/xyz-product$ /categories/dogs/leash/products/xyz-product permanent;
  rewrite ^/categories/cats-c-litter-box/products/xyz-product$ /categories/cats/litter-box/products/xyz-product permanent;
}

想使用一行正则表达式并替换-c-/

4

1 回答 1

0

请试试这个

try_files $uri/index.html $uri @moved;

location @moved {
    rewrite ^/categories/(.+)-c-(.+)$ "/categories/$1/$2" permanent;
}

并且要小心斜线,因为 $URI 总是以斜线 (/) 开头,所以在重定向到新的“移动”场景后,它应该是一样的。

于 2013-08-12T16:10:04.513 回答