我想將所有請求重定向到
www.example.com/page
到
www.example.com/new-page
這意味著www.example.com/page用新的替換,例如:
www.example.com/page
301 > www.example.com/new-page
www.example.com/page/1
301 >www.example.com/new-page/1
www.example.com/page/1.png
301 >www.example.com/new-page/1.png?1
www.example.com/page/common/1.png
301 >www.example.com/new-page/common/1.png?1
www.example.com/page123
301 >www.example.com/new-page123
我怎么能那樣做?
uj5u.com熱心網友回復:
使用帶有類似redirect引數的重寫
location /page/ {
rewrite ^/page/(.*)$ /new-page/$1 permanent;
}
我的測驗
127.0.0.1 - - [12/Feb/2022:10:20:42 0000] "GET /page/test/123 HTTP/1.1" 301 169 "-" "curl/7.74.0" "-"
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.21.6
< Date: Sat, 12 Feb 2022 10:20:42 GMT
< Content-Type: text/html
< Content-Length: 169
< Location: http://127.1/new-page/test/123
< Connection: keep-alive
<
* Ignoring the response-body
* Connection #0 to host 127.1 left intact
* Issue another request to this URL: 'http://127.1/new-page/test/123'
* Found bundle for host 127.1: 0x561d293f5970 [serially]
* Can not multiplex, even if we wanted to!
* Re-using existing connection! (#0) with host 127.1
* Connected to 127.1 (127.0.0.1) port 80 (#0)
> GET /new-page/test/123 HTTP/1.1
> Host: 127.1
> User-Agent: curl/7.74.0
> Accept: */*
>127.0.0.1 - - [12/Feb/2022:10:20:42 0000] "GET /new-page/test/123 HTTP/1.1" 200 3 "-" "curl/7.74.0" "-"
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.21.6
< Date: Sat, 12 Feb 2022 10:20:42 GMT
< Content-Type: application/octet-stream
< Content-Length: 3
< Connection: keep-alive
<
OK
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/428592.html
標籤:nginx
上一篇:嘗試在Nginx服務器Ubuntu21.10實體上部署我的燒瓶應用程式時,我遇到了經典的“連接上游時權限被拒絕”
下一篇:如何在nginx入口中捕獲子域
