skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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 ... ?


  2. 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;
    
    1. First, it redirects the end .html
    2. Second, it redirects the middle .html

    I require it to be in a single span. Any !dea?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search