我需要将/forum和/forums重定向到一个名为/new的新文件夹。这是为了捕捉名称/类型o的变化,它不能用作别名指令。
我需要这样的:
/forum to /new
/forum/ to /new/
/forums to /new
/forums/ to /new/
/forum/blah to /new/blah
/forum/wee/blah.jpg to /new/wee/blah.jpg我正在拔头发,我知道这很简单,但我试过十几个例子,但都搞不懂。
使用:
location /forum {
return 301 $scheme://$host/new;
}仅适用于/forum,不适用于/ /forum/blah (需要转到/new/blah)。
02:22 AM [atlantis]/etc/nginx/sites root # curl -I xxx/forum
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sat, 12 Sep 2015 06:22:06 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: http://xxx/new
Strict-Transport-Security: max-age=63072000
X-Content-Type-Options: nosniff
02:22 AM [atlantis]/etc/nginx/sites root # curl -I xxx/forum/blah
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sat, 12 Sep 2015 06:22:12 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: http://xxx/new
Strict-Transport-Security: max-age=63072000
X-Content-Type-Options: nosniff发布于 2015-09-12 17:56:39
试试这个:
location ~ ^/forums(.*)$ {
return 301 /new$1;
}
location ~ ^/forum(.*)$ {
return 301 /new$1;
}“返回”指令比“重写”更可取。
https://stackoverflow.com/questions/32535884
复制相似问题