问题
I want do a redirect from old url:
http://example.org/xxxxxxxxx.html
To new urls (remove ".html")
http://example.org/xxxxxxxxx
How I can do this with nginx?
EDIT:
xxxxxxxxx
can be differ, example:
http://example.org/url-1.html
redirect to http://example.org/url-1
http://example.org/another-url.html
redirect to http://example.org/another-url
回答1:
location ~ ^(.*)\.html$ {
return 301 $1;
}
回答2:
Probably you need a rewrite statement
location /xxx.html {
rewrite ^/xxx(.*) http://example.org/xxxxx permanent;
}
You detailed explanation please refer https://www.nginx.com/blog/creating-nginx-rewrite-rules/
Another method would be return directive
server {
listen 80;
listen 443 ssl;
server_name www.old-name.com old-name.com;
return 301 $scheme://www.new-name.com;
}
回答3:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.org www.example.org;
return 301 http://$server_name$request_uri;
}
来源:https://stackoverflow.com/questions/38171713/redirect-with-nginx-remove-substring-from-url