I have the following in my nginx.conf:
location ~* /collections.*?products/([^/]+)/?$ {
rewrite ^/collections.*?products/([^/]+)/?$ /$1.html;
rewrite ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3;
rewrite ^([^_]*)_(.*)$ $1-$2 permanent;
}
To rewrite requests such as
"/collections/products/someproduct/" to "/someproduct.html"
"/collections/products/some_product/" to "/some-product.html"
"/collections/products/some_other_product/" to "/some-other-product.html"
However I can only get a 301 redirect to occur if the last rewrite directive (containing the permanent
flag) matches and processes, e.g. my 2nd example. In the other 2 instances I get a 302 temporary redirect. How can I process these multiple rewrite directives in this location block and return 301 redirect regardless which ones match? If I put a permanent flag on all rewrite directives, it will stop processing after first match.