【发布时间】:2015-09-12 06:23:37
【问题描述】:
我需要将 /forum 和 /forums 重定向到一个名为 /new 的新文件夹。这是为了捕捉 name/type-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
【问题讨论】:
-
为什么是 HTTP 301 而不是 Nginx 重写指令?
-
我尝试了两种方式。将采取任何有效的方法