问题
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