Redirect 使用nginx重定向(从url中删除子字符串)

Redirect 使用nginx重定向(从url中删除子字符串),redirect,nginx,url-rewriting,url-redirection,ngx-http-rewrite-module,Redirect,Nginx,Url Rewriting,Url Redirection,Ngx Http Rewrite Module,我想从旧url执行重定向: http://example.org/xxxxxxxxx.html 添加新URL(删除“.html”) 如何使用nginx实现这一点 编辑: xxxxxxxxx可以不同,例如: http://example.org/url-1.html重定向到http://example.org/url-1 http://example.org/another-url.html将重定向到http://example.org/another-url您可能需要重写语句 location

我想从旧url执行重定向:

http://example.org/xxxxxxxxx.html
添加新URL(删除“.html”)

如何使用nginx实现这一点

编辑

xxxxxxxxx
可以不同,例如:

http://example.org/url-1.html
重定向到
http://example.org/url-1

http://example.org/another-url.html
重定向到http://example.org/another-url

您可能需要重写语句

location /xxx.html {
   rewrite ^/xxx(.*) http://example.org/xxxxx permanent;
 }
详细解释请参考

另一种方法是return指令

server {
    listen 80;
    listen 443 ssl;
    server_name www.old-name.com old-name.com;
    return 301 $scheme://www.new-name.com;
}

@rpayanm在配置中尝试上述方法,如果您遇到任何问题,请告诉我。op,我的回答是否满足您的问题?如果是,请投票并接受!如果没有,请随时提供它不足之处的澄清,如果有。感谢接受并投票,+1您的方式!
server {
    listen 80;
    listen 443 ssl;
    server_name www.old-name.com old-name.com;
    return 301 $scheme://www.new-name.com;
}
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.org www.example.org;
    return 301 http://$server_name$request_uri;
}
location ~ ^(.*)\.html$ {
    return 301 $1;
}