2011-08-11 21 views
1

我希望爲移動設備用戶的請求只能http://mydomain.com/video.html重定向到http://mydomain.com/mobile/index.html移動用戶特定的頁面請求目前這是一個WordPress的網站,所以已經有一些WordPress的東西在我的。 htaccess文件。使用的.htaccess</p> <p>重定向僅適用於使用htaccess的

這是我現在有:

AddHandler php5-script .php 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 

# BEGIN Mobile redirect for the video 
<IfModule mod_rewrite.c> 
RewriteEngine on 

    # stuff to let through (ignore) 
    RewriteCond %{REQUEST_URI} "/mobile/" 
    RewriteRule (.*) $1 [L] 
    # 
RewriteCond %{REQUEST_URI} !^/html/video.html.*$ 
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] 
RewriteRule ^(.*)$ /mobile/index.html [L,R=302] 
</IFModule> 
# END Mobile redirect 

這是目前重定向我的iPad的所有網頁,而不是爲網頁我希望它(video.html)

我缺少的東西?

回答

2

試試這個:

# BEGIN Mobile redirect for the video 
<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # stuff to let through (ignore) 
    RewriteRule ^mobile/ - [L] 
    # redirect /video.html to /mobile/index.html for mobile browsers 
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] 
    RewriteRule ^video\.html$ /mobile/index.html [L,R=302] 
</IfModule> 
# END Mobile redirect 

1.因爲你的WordPress這將是更好地把這個塊之前的WordPress塊。

2.如果你在這個塊中有很少的重寫規則(特別是如果你在WordPress之前放置整個塊),那麼# stuff to let through (ignore)規則並不是真的需要。但是因爲我不確定你的網站是如何工作的,所以我把它留給你測試。

3.我看你在RewriteRule中使用(.*)模式,然後在RewriteCond中使用一個額外的模式來做實際的URL匹配。沒有必要 - 你可以在RewriteRule中完成所有這些。

例如,這樣的:

RewriteCond %{REQUEST_URI} "/mobile/" 
RewriteRule (.*) $1 [L] 

可以很容易地通過

RewriteRule ^mobile/ - [L] 
+0

謝謝你的答案被替換。我只是嘗試了你的解決方案,現在它不再重定向任何東西。所以它解決了一個問題 - 重定向其他頁面,但我仍然有問題將它重定向video.html到/mobile/index.html。 – flyboy

+0

我應該提一下,我已經嘗試了WordPress塊前後的新塊,獲得了相同的結果,但現在已經根據您的建議將其留在了現在。 – flyboy

+0

此外,爲了響應你的#2,我有這條線,因爲沒有它,我得到一個Apache錯誤的重定向太多。隨着這條線路的到來,重定向不再重複。合理? – flyboy