Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can i remove the .html from an url with argument?



I have tried

    location / {
    index index.html index.php; 
            rewrite ^\.html(.*)$ $1 last;
            try_files $uri $uri/ @handler; 
            expires 30d; ## Assume all files are cachable

and a bunch of other suggestions, but can't seem to make it work....


share|improve this question
up vote 5 down vote accepted

Modify your configuration like this:

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

location / {
    index index.html index.php;
    # this way nginx first tries to serve the file as an .html although it doesn't have the extension
    try_files $uri.html $uri $uri/ @handler;

Ofcourse you can add any cache settings etc. but this should be enough to remove the .html part.

share|improve this answer
Yes! Thank you Jagsler! – Nicovs_be Oct 17 '12 at 18:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.