I want my nginx make display all url's clean.
- http://www.mydomain.com/indexhtml.html as http://www.mydomain.com/indexhtml
- http://www.mydomain.com/indexphp.php as http://www.mydomain.com/indexphp
With some research I've made the first case to work. It`s done by following configuration:
location / {
root html;
index index.html index.htm index.php;
try_files $uri.html $uri/ =404;
}
It works for indexhtml.html displaying as indexhtml, but nothing happens with .php. If I change $uri.html to $uri.php, it works neither for .html, neither .php. I`ve tried to put something similar in php location but without any success.
Any advices?
To further Mohammad's answer, you might also want to offer redirects from
.html
and.php
to the extensionless versions.This can be accomplished due to the fact that
$request_uri
contains "full original request URI (with arguments)", and is not affected by the internal rewrites that are not visible to the user.Perhaps this may be of use for you... It' Simple and gets the job done:
No need for extra blocks and named locations and everything. Also move the
index
line outside the location blockKeep in mind that if you have a folder and a file with the same name inside the same folder, like
/folder/xyz/
and/folder/xyz.php
you won't be able to run the php file if the folderxyz
contains anindex.php
orindex.html
, just keep this in mind.From what I've researched, if you append your /etc/nginx/conf.d/domain.tld.conf file to include:
Then restart nginx and give it a go. Hopefully this will help you! More information can be found (where I found it) here @ tweaktalk.net