Removing .html from a link using NGINX

走远了吗. 提交于 2020-03-25 08:42:30

问题


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:


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/
    }
}


来源:https://stackoverflow.com/questions/54581362/removing-html-from-a-link-using-nginx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!