Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Rewriting index and stripping .html

$
0
0
Hi,

For the last few hours I have been attempting to configure nginx, but I still have one last issue.
What I'm trying to archieve is:

- Only serve .html files
- Example.com => Example.com (serving index.html)
- Example.com/index => Example.com (serving index.html)
- Example.com/index.html => Example.com (serving index.html)
- Example.com/foo => Example.com/foo (serving /foo.html)
- Example.com/foo.html => Example.com/foo (serving /foo.html)
- Example.com/NonExistingURL => Example.com (serving index.html)

So far I only managed to cover some of those above, but never all of them combined.
This is what I currently have:

index index.html index.htm;

location / {
try_files $uri.html $uri/ =404;
}

rewrite ^(/.+)\.html$ $scheme://$host$1 permanent;

error_page 403 404 405 = @homepageredirect;

location @homepageredirect {
rewrite .* / permanent;
}

It does most of what I want, the only problem left I have, is that the root always shows /index, as in Example.com/index.
Example.com also sadly redirects to Example.com/index
The other redirects seems to work.
Any hint? Thanks in advance!

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>