If a file with ".html" extension doesn't exist I need to know if the same file exists with ".th.html" extension and make a redirect.
Right now on 404 I'm doing a rewrite and if $request_filename exists I do the redirect.
try_files $uri $uri/ @thengine;
error_page 404 = @thengine;
location @thengine {
rewrite ^/(.*)\.(htm|html)$ /$1.th.html;
if (-f $request_filename) {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_intercept_errors on;
proxy_redirect off;
proxy_pass http://thengine_backend;
}
}
I'm wondering if there is a better way to do that without rewrite.
Maybe something like
if ($request_filename ~ (some rule to replace extension)){...}
Thank you.
Edit: All requests from browser will come with .html, but in case the file with .html doesn't exist, I have to check if the same file exists with .th.html and do redirect only on this case.
Edit2: Let's say someone access domain-nginx.com/path/to/index.html
- nginx must check if file exist, and if it does, show the page
- if file doesn't exist, look for index.th.html
- if index.th.html doesn't exist give directly 404
- if index.th.html DOES exist set some headers and
serve domain-app.com/path/to/index.th.html
(here is an application that will process these kind of templates)
All this time the user must see only domain-nginx.com/path/to/index.html
and not see any redirect or the url to change.
Notice that .th.html is handled by another application