Welcome! Log In Create A New Profile

Advanced

Rewriting index and stripping .html

Posted by sparr0w 
Rewriting index and stripping .html
October 22, 2014 12:56PM
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!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 211
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready