redir
對客戶端發出 HTTP 重新導向。
此指令暗示已比對的要求將原樣遭拒,而客戶端應嘗試在不同的 URL 中再次執行。因此,其 指令順序 非常靠前。
語法
redir [<matcher>] <to> [<code>]
-
<to> 是目標位置。成為回應的
Location
標頭。
-
<code> 是用於重新導向的 HTTP 狀態碼。可以是
-
3xx
範圍內的正整數,或401
-
temporary
,表示暫時重新導向(302
,這是預設值) -
permanent
,表示永久重新導向(301
) -
html
,使用 HTML 文件執行重新導向(對於重新導向瀏覽器有用,但對 API 客戶端則無用) -
具有狀態碼值的佔位符
-
範例
將所有要求重新導向至 https://example.com
www.example.com {
redir https://example.com
}
相同,但透過附加 {uri}
佔位符 來保留現有的 URI
www.example.com {
redir https://example.com{uri}
}
相同,但為永久性
www.example.com {
redir https://example.com{uri} permanent
}
將舊的 /about-us
頁面重新導向至新的 /about
頁面
example.com {
redir /about-us /about
reverse_proxy localhost:9000
}