Reputation: 5434
I would like to create a rule in my NGINX config file to add this functionality:
if:
www.mydomain.com/*
gives out 404
I would like NGINX to redirect to www.mydomain.com/*-obsolete
.
for example, if a user navigates to:
www.mydomain.com/testpage
and 404
is to be returned, I'd like NGINX to redirect to www.mydomain.com/testpage-obsolete
to try and avoid the 404
.
How is that done?
Upvotes: 0
Views: 377
Reputation: 15478
For example:
location / {
try_files $uri $uri-obsolete $uri/ $uri-obsolete/ =404;
}
More complex case, showing obsolete html files:
location ~ ^(.*)/([^/]+)\.(html?)$ {
set $file $1/$2;
set $ext $3;
try_files $file.$ext $file-obsolete.$ext =404;
}
Upvotes: 1