只重定向使用htaccess的移动用户特定的页面请求 [英] Redirecting only a specific page request for mobile users using htaccess

查看:130
本文介绍了只重定向使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆