0

If a user hits a 404 I'd like the user to be redirected to the parent category.

The expected behaviour I'm looking for is the following examples

www.test.co.uk/category/product404page > www.test.co.uk/category/

www.test.co.uk/anothercategory/morecategories/product404page > www.test.co.uk/anothercategory/morecategories/

So something like the the following is required

location ^~ /dynamicrecursivedir/ {
try_files $uri ../;
}

Is this possible?

1 Answer 1

0

Obviously you will need to tweak the regex for your specific requirements. I needed to use two locations to prevent a redirect loop.

location ~ ^(/.*)/$ {
   index index.html;
}
location ~ ^(/.*)/[^/]+$ {
   error_page 404 =301 $scheme://$host$1/;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .