Welcome! Log In Create A New Profile

Advanced

How to remove all .html from the URL | Nignx

Posted by eligiable 
How to remove all .html from the URL | Nignx
August 20, 2017 09:53AM
I'm new to Nginx, I need to remove all the *.html extensions appear in my URL, e.g. http://mywebsite.com/events.html/beauty-must-haves.html

I've tried lots of solutions to fix this, but not able to fix, can anyone kindly help me to fix this. These are no hard coded pages, it generates at runtime the following link doesn't help fix it.

how to serve html files in nginx without showing the extension in this alias setup

I need it to be SEO Friendly e.g. http://mywebsite.com/events/beauty-must-haves

Thanx in Advance.
Re: How to remove all .html from the URL | Nignx
August 21, 2017 02:42AM
The following code got me what I was looking for, but it doesn't remove the .html extension inside the URL, it only removes the ending extension:

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

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

Any Help Please ... ?
Re: How to remove all .html from the URL | Nignx
August 22, 2017 04:13AM
The following code works for me to hide the Extensions in the Middle of the URL, but it's redirecting twice:

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

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

First, it redirects the end .html
Second, it redirects the middle .html
I require it to be in a single span. Any !dea?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 281
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