htaccess的重定向黑莓不工作 [英] .htaccess redirect for blackberry not working
问题描述
我想通过做重定向黑莓用户到我的手机网站:
I am trying to redirect blackberry users to my mobile site by doing:
# redirect for blackberry users
RewriteCond %{HTTP_USER_AGENT} ^.BlackBerry.$
RewriteRule ^(.*)$ http://www.domain.com/m/ [R=301]
在我的.htaccess,但是当我尝试从设备访问什么也没有发生,我已经删除缓存和COOKIS并没有什么作品。我一直在谷歌上搜索周围,似乎我是在做正确的重定向,但我想不会,我缺少什么?
in my .htaccess, but nothing happens when I try to access from the device, I've already deleted cache and cookis and nothing works. I have been googling around and it seems I'm doing the redirect correctly but I guess not, what am I missing?
我的.htaccess只包含的方式。
My .htaccess only contains that by the way.
修改 在我的服务器的根目录下的.htaccess。
Edit The .htaccess in my server's root.
推荐答案
如果这不是你的.htaccess文件中唯一的规则,你可能有一个问题,以后的规则搅乱你的重定向。要立即重定向,你需要包括→
标记。
If this isn't the only rule in your .htaccess file, you might have an issue where a later rule messes up your redirect. To redirect immediately, you need to include the L
flag.
我还怀疑你的正常的前pression用户代理可能是不正确的,你要测试对输入,由于两个。
比赛刚一个字符的单词黑莓的任一侧。这也将是一个不错的主意,以防止重定向循环与检查,看看是否你已经在 / M /
(但如果你有一个mod_rewrite的指令。在该目录中它并不重要)htaccess文件。
I also suspect that your regular expression for the user agent is probably not correct for the input you're testing against, since the two .
match just one character on either side of the word "BlackBerry". It would also be a good idea to guard against a redirect loop with a check to see if you're already in /m/
(although if you have mod_rewrite directives in a .htaccess file in that directory it's not important).
把所有的一起,我们得到类似如下:
Putting all of that together, we get something like the following:
# Check for x-wap-profile/Profile headers
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ [OR]
# Check for BlackBerry anywhere in the user agent string
RewriteCond %{HTTP_USER_AGENT} BlackBerry [NC]
# Make sure we're not in /m/ already
RewriteCond %{REQUEST_URI} !^/m/
RewriteRule ^ http://example.com/m/ [R=301,L]
您可能还需要该重写规则
是
RewriteRule ^.*$ http://example.com/m/$0 [R=301,L]
...如果内容被命名为在 / M /
目录相同(但移动友好的)。
...if the content is named the same (but mobile-friendly) in the /m/
directory.
这篇关于htaccess的重定向黑莓不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!