我有一個新域,需要通過 Apache 中的代理加載舊域的內容。這已經很好了:
<VirtualHost myserver:80>
ServerName newdomain.com
ServerAlias www.newdomain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^newdomain\.com$
RewriteRule ^(.*)$ https://olddomain.com/$1 [P]
</VirtualHost>
例如:
newdomain.com/contact負載olddomain.com/contactnewdomain.com/catalogue/342負載olddomain.com/catalogue/342
但是當我嘗試這個時問題就來了:
newdomain.com(沒有任何額外的路徑)。結果是 404 錯誤。
我幾乎猜測問題出在RewriteCond/RewriteRule定義中,但我似乎找不到問題所在。有任何想法嗎?謝謝!
uj5u.com熱心網友回復:
RewriteRule ^(.*)$ https://olddomain.com/$1 [P]
由于此規則是在虛擬主機背景關系中定義的,因此RewriteRule 模式匹配的 URL 路徑是相對于根的,并以斜杠開頭。由于它被捕獲并在替換字串中使用,因此將在目標 URL 路徑的開頭產生雙斜杠。
也許這正在拋棄主頁的路由。
請嘗試以下操作:
RewriteRule ^/(.*)$ https://olddomain.com/$1 [P]
也不需要前面的RewriteCond指令,因為您已經在 vHost for 中newdomain.com并且當前條件省略了www.newdomain.com,這可能不是意圖。
或者根本不使用 mod_rewrite,因為它似乎是一個直接的一對一代理。
例如,請改用以下內容。
ProxyPass / https://olddomain.com/
ProxyPassReverse / https://olddomain.com/
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/334785.html
