
假設我有 exampleA.com 和 exampleB.com。如果我希望在 Apache Web 伺服器上執行從 websiteA.com 到 websiteB.com 的重寫,就像當我在瀏覽器中輸入 exampleA.com 時,它將保留 URL 並顯示載入的內容,就像我導航到exampleB.com,我該如何直接新增虛擬主機?
我的研究顯示:
RewriteRule /some/url(.*) http://exampleB.com/some/url$1 [P,L]
但我不熟悉的是「/some/url」部分的相關性,因為我不希望只重寫特定的 URI,而是重寫整個網域。
同樣,如果我導航到 exampleA.com/test.htm,它應該呈現 exampleB.com/test 中的任何內容,瀏覽器始終顯示「exampleA.com/test」。
答案1
要將該規則套用到整個網域,您需要..
RewriteRule /(.*) http://exampleB.com/$1 [P,L]
這基本上與以下內容相同:
ProxyPass / http://exampleB.com/
請記住,有很多事情可以將使用者的瀏覽器指向該exampleB
網域。 ProxyPassReverse
將處理30x
重定向:
ProxyPassReverse / http://exampleB.com/
但內容中的其他任何內容都可能指向exampleB.com
,包括 HTML 內容(mod_proxy_html
可能有幫助)、javascript、CSS 等。
答案2
你不能。
如果你想保留原始 URL,你需要透過 examplea 實際代理(尋找 ProxyPass)exampleb 或使用某種框架惡作劇。