2014-01-16 46 views
0

我在我的網站mobil.test.nu上有重定向規則。完成DNS更改後,舊重定向會發生什麼

# For mobile devices: 
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|iphone|ipod|windows\ phone) [NC] 
RewriteRule^http://test.nu/ [L,R=301] 

# For non-mobile devices: 
RewriteRule ^/?$ http://test.nu/mobil/index.htm [L,R=301] 
RewriteRule ^(.*)$ http://test.nu/mobil$1 [L,R=301] 

一些請求重定向到test.nu.

我正在做的測試.nu的mobil.test.nu的DNS更改。

我認爲我不得不重寫所有的請求,這些請求是來自mobil.test.nu,再次在test.nu中。

有人能告訴我如何在dns更改後識別來自mobil.test.nu的請求。

編輯 識別主機名和修改。

# For mobile devices: 
RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC] 
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|iphone|ipod|windows\ phone) [NC] 
RewriteRule^http://test.nu/ [L,R=301] 

# For non-mobile devices: 
RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC] 
RewriteRule ^/?$ http://test.nu/mobil/index.htm [L,R=301] 
RewriteRule ^(.*)$ http://test.nu/mobil$1 [L,R=301] 

回答

1

您需要添加檢查針對%{HTTP_HOST}可變條件:

# For mobile devices: 
RewriteCond %{HTTP_HOST} !^mobile\.test\.nu$ [NC] 
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|iphone|ipod|windows\ phone) [NC] 
RewriteRule^http://mobile.test.nu/ [L,R=301] 

# For non-mobile devices: 
RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC] 
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|iphone|ipod|windows\ phone) [NC] 
RewriteRule ^/?$ http://test.nu/mobil/index.htm [L,R=301] 

RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC] 
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|iphone|ipod|windows\ phone) [NC] 
RewriteRule ^(.*)$ http://test.nu/mobil$1 [L,R=301] 

並不完全清楚你的規則應該怎麼做,因爲我不覺得上面去上班做。但本質上是:

RewriteCond %{HTTP_HOST} ^mobile\.test\.nu$ [NC] 

會告訴你該請求是否是mobile.test.nu與否。

+0

謝謝你的回答。我想,我可以確定主機並按照您的建議書寫規則。 – Patan

+0

請幫我檢查他們是否正確的規則不是。我編輯了我的問題。 – Patan

+0

即使在DNS更改之後,我是否能夠使用RewriteCond%{HTTP_HOST}^mobile \ .test \ .nu $捕獲原始主機[NC] – Patan