2

我想从旧网址重定向:

http://example.org/xxxxxxxxx.html

到新网址(删除“.html”)

http://example.org/xxxxxxxxx

我怎么能用 nginx 做到这一点?

编辑

xxxxxxxxx可以不同,例如:

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

4

3 回答 3

4
location ~ ^(.*)\.html$ {
    return 301 $1;
}
于 2016-07-03T20:31:28.187 回答
1

可能你需要一个重写语句

location /xxx.html {
   rewrite ^/xxx(.*) http://example.org/xxxxx permanent;
 }

你的详细解释请参考https://www.nginx.com/blog/creating-nginx-rewrite-rules/

另一种方法是返回指令

server {
    listen 80;
    listen 443 ssl;
    server_name www.old-name.com old-name.com;
    return 301 $scheme://www.new-name.com;
}
于 2016-07-03T16:03:10.090 回答
0
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.org www.example.org;
    return 301 http://$server_name$request_uri;
}
于 2016-07-03T16:04:11.897 回答