1

I've this configuration for my nginx site-available file. It creates a link like https://website.com/news-id.html

What i want to do is to remove "news-" and .html from the link and make the url clean with just https://website.com/id

I have tried several methods but everytime i run into a redirection loop.

**I tried several times to put the code here but failed. So here is the link to the config file https://jpst.it/1AKIf

1
  • 3
    I have tried several methods share those with us
    – castis
    Feb 7, 2019 at 20:07

1 Answer 1

1

Try this config.

server {
    location / {

        # Redirects to the version without .html
        if ($request_uri ~ ^/(.*)\.html$) {  return 302 /$1;  }

        # Tries the uri, .html file and the news prefix.
        try_files $uri $uri/ $uri.html news-$uri news-$uri/
    }
}
1
  • Thanks for this. It took around 3 hours to find it. Mar 5, 2020 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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