我喜歡重定向我的網站。
我現在有:
https://www.old.example/NL/page
它必須成為
https://www.new.example/page
我知道我可以更改域
通常我會使用這樣的東西,但這只會改變域:
RewriteCond %{HTTP_HOST} ^old.example/NL$ [OR]
RewriteCond %{HTTP_HOST} ^www.old.example/NL/$
RewriteRule (.*)$ https://www.new.example/$1 [R=301,L]
所以現在我在想這樣的事情:
RewriteRule %{HTTP_HOST} ^old.example/(NL)/([A-Za-z0-9_-]*)$ http://www.new.example/$2&%{QUERY_STRING} [R=301,L]
但這給出了以下結果:
http://www.new.example/NL/page
誰能幫我找到正確的解決方案?
uj5u.com熱心網友回復:
HTTP_HOSTserver 變數包含請求標頭的值(Host即主機名),它不包含 URL 路徑,因此您的規則都不會做任何事情(事實上,第二條規則完全無效)。
您可以改為執行以下操作:
RewriteCond %{HTTP_HOST} ^(www\.)?old\.example [NC]
RewriteRule ^NL/(.*) https://www.new.example/$1 [R=301,L]
表單的所有 Apache 服務器變數都HTTP_<NAME>參考相應的 HTTP 請求標頭<NAME>。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/459229.html
