I have read a dozen rewite questions. Most questions are for .php but I have simple .html files so about => about.html .But I am not able to get nginx to do this:
- accept url with or without "/"
- redirect domain.com/about and domain.com/about/ to domain.com/about.html
- add trailing slash to the URL so if I write domain.com/about it writes domain.com/about/
I have tried with this code
rewrite ^/([a-zA-Z0-9]+)$ /$1.html;
but it gives me 404 error on url ending with "/". Also tried this
rewrite ^([a-zA-Z0-9]+)/?$ $1.html
with same error.
Some suggest I should be using try try_files
?
I tried this also which gives a 500 error:
location / {
rewrite ^(.*)$ /%1 redirect;
rewrite ^/([^\.]+)$ /$1.html break;
}
I tried to convert apache to nginx (winginx.com) from suggestion here with no success.
This code does not work. I am trying to redirect and add trailing slash:
if (!-e $request_filename){
rewrite ^/(.*)/$ /$1 redirect;
}
if (!-e $request_filename){
rewrite ^/(.*[^/])$ /$1/ redirect;
}
Any suggestion would make me happy.