Web Servers

How To Remove html Extension In Nginx

If you want to know how to remove html extension in Nginx, this tutorial will help you.

1. Edit website’s configuration using following command:

# vi /etc/nginx/site-available/example.com.conf

Note: The path of the configuration file maybe different in your server. Replace example.com.conf to your website’s conf file name.

2. Add following code:

rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;
rewrite ^/(.*)/$ /$1 permanent;

try_files $uri/index.html $uri.html $uri/ $uri =404;

Save and exit.

3. Restart Nginx service to apply the changes

# systemctl restart nginx

That’s it. Now verify it by access the html pages.

In this tutorial, we have seen how to remove html extension in Nginx.

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles