2012-10-16 64 views
0

我想結合重寫和代理服務器通行證,並遇到重寫問題。這是我有什麼apache用代理服務器重寫

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example.world.net 
RewriteRule %{HTTP_HOST} http://newexample.newworld.net:7802/apex/f?p=208 [R,P] 
ProxyPass/http://newexample.newworld.net:7802/ 

proxypass正在工作,但我不知道如何獲得最初的重定向。因此,如果用戶放入example.world.net/apex/f?p=208,它會轉到newexample.newworld.net:7802/apex/f?p=208並掩蓋該網址。

但是,如果apex/f?p = 208不在url中,我需要將example.world.net重定向到example.world.net/apex/f?p=208。

回答

2

您不能同時將代理重定向。您的重寫規則標誌是[R,P],它是「重定向」和「代理」。你需要一個或另一個在這裏。此外,您的規則的正則表達式永遠不會匹配%{HTTP_HOST},除非您的網址字面上是:http://example.world.net/%{HTTP_HOST}。你需要將它更改爲:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example.world.net 
RewriteCond %{QUERY_STRING} !(^|&)p=208(&|$) 
RewriteRule ^/?$ /apex/f?p=208 [L,QSA,R] 

這如果URL地址欄說:http://example.world.net/http://example.world.net/apex/f?p=208會將瀏覽器重定向。然後,取決於代理取/apex/f?p=208並將其代入http://newexample.newworld.net:7802/

有可能mod_proxy和mod_rewrite不會很好地結合在一起,因爲兩者最終都可以應用到同一個URL。如果您發現兩者都得到在同一時間應用,然後更改ProxyPass行:

RewriteRule ^/?(.*)% http://newexample.newworld.net:7802/$1 [L,P,QSA] 
+0

這很好。我不必添加您提到的最後一次重寫。它與代理通行證一起工作。謝謝 – user1733616

0

所以,你要example.world.net重定向到http://newexample.newworld.net:7802/apex/f?p=208example.world.net/apex/f ?p = 208?我假設前者,如果我錯誤地將RewriteRule中的url更改爲後者。

但我認爲這應該這樣做

RewriteCond %{HTTP_HOST} ^example.world.net$ [NC] 
RewriteRule %{HTTP_HOST} http://newexample.newworld.net:7802/apex/f?p=208 [R,L] 

但隨後它是未知的名稱是什麼/你的虛擬主機的別名,讓/在

的ProxyPass/http://newexample.newworld.net:7802/

可能會打破所有。

+0

對不起它沒有工作example.world.net沒有得到重定向到example.world.net。它保持不變,並在後端去newexample.newworld.net:7802。 – user1733616