只重定向使用htaccess的移动用户特定的页面请求 [英] Redirecting only a specific page request for mobile users using htaccess
问题描述
我要重定向移动用户的请求才 http://mydomain.com/video.html使用的.htaccess http://mydomain.com/mobile/index.html
I want to redirect requests for mobile users only to http://mydomain.com/video.html to http://mydomain.com/mobile/index.html using .htaccess
目前它的一个字preSS网站,所以已经有一些字preSS东西在我的.htaccess文件。
Currently it's a Wordpress site, so there is already some Wordpress stuff in my .htaccess file.
下面是我现在的:
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)
It is currently redirecting my iPad for all pages, and NOT for the page I want it to (video.html)
我缺少的东西?
推荐答案
试试这个:
# 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。因为你有话语preSS这将更好地把这个块之前,道preSS块。
1. Because you have WordPress it will be better to place this block BEFORE WordPress block.
2。有没有真正的需要#的东西,让通过(忽略)
的规则,如果你有那么一点重写规则在此块(尤其是如果你把整个街区字$ P $前PSS的一个)。但因为我不知道如何确定你的网站做的工作,我让你来测试。
2. There is no real need for # stuff to let through (ignore)
rule if you have so little rewrite rules in this block (especially if you place whole block before WordPress one). But since I do not know for sure how your website works, I leave it for you to test.
3。我看你是使用(。*)
格局重写规则..并在随后的RewriteCond一个额外的模式做实际的URL匹配。没有必要 - 你可以做所有这一切在重写规则本身
3. I see you are using (.*)
pattern in RewriteRule .. and then one extra pattern in RewriteCond to do actual URL matching. No need -- you can do all of that in RewriteRule itself.
例如,这样的:
RewriteCond %{REQUEST_URI} "/mobile/"
RewriteRule (.*) $1 [L]
可以很容易地通过
can easily be replaced by
RewriteRule ^mobile/ - [L]
这篇关于只重定向使用htaccess的移动用户特定的页面请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!