2014-02-06 27 views
0

我需要多個RewriteCond爲同一個域,但不同的REQUEST_URIs 我需要根據REQUEST_URI重定向到一個不同的域。Apache重定向 - 相同的域不同REQUEST_URI

我沒有運氣嘗試此:

RewriteCond %{HTTP_HOST} ^(www.)?example.com$  
RewriteCond %{REQUEST_URI} !^/myuir/ [OR] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule (.*)$/[R=301,L] 

RewriteCond %{HTTP_HOST} ^(www.)?example.com$  
RewriteCond %{REQUEST_URI} !^/myuniqueuri/ [OR] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule (.*)$ http://example2.com/$! [R=301,L] 

RewriteCond %{HTTP_HOST} ^(www.)?example.com$  
RewriteCond %{REQUEST_URI} !^/myotheruniqueuri/ [OR] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule (.*)$ http://example3.com/$! [R=301,L] 

我認爲[OR]請求URI條件會的工作,但事實並非如此。我也試過沒有[OR],它沒有工作!

例如:

如果URL是:

http://example.com/myuniqueuri 

需要重定向到:

http://example2.com 

如果URL是:

http://example.com/myotheruniqueuri 

需要重定向到:

http://example3.com 

其中example2和example3可以是任何東西,但不是相同的。

任何幫助是極大的讚賞

感謝

+0

您能否準確解釋您期望的每個重定向如何工作? –

回答

0

我想問題可能是你的語法。參考是$ 1不是$ !. !也被錯誤地使用。這基本上意味着not。如果沒有這個目錄,那麼等等。好吧,看來你想匹配的目錄,然後重定向的基礎上。試試這段代碼,看看它是否適合你。

RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/myuir 
RewriteRule ^(.*)$/[R=301,L] 

RewriteCond %{REQUEST_URI} ^/myuniqueuri 
RewriteRule ^(.*)$ http://example2.com/ [R=301,L] 

RewriteCond %{REQUEST_URI} ^/myotheruniqueuri 
RewriteRule ^(.*)$ http://example3.com/ [R=301,L] 
相關問題