htaccess RewriteCond让web.com / m的请求保持不变

时间:2012-04-18 18:54:04

标签: apache .htaccess mod-rewrite apache2

在手机中,如果用户尝试访问website.com,则会将其重定向到mobile.website.com。但是,mobile.website.comwebsite.com发出了AJAX请求,因此我将所有请求都通过website.com/m/...。这不起作用:

# redirect phones/tablets to mobile site
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{HTTP_HOST} !mobile\.website\.com [NC]
RewriteCond %{REQUEST_URI} !^/m/ [NC]
RewriteRule ^(.*)$ http://www.mobile.website.com/$1 [L,R=302]

特别是这一行:

RewriteCond %{REQUEST_URI} !^/m/ [NC]

如果网址与website.com/m/...匹配,则应取消重写规则。有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

使用以下代码更改您的代码:

# redirect phones/tablets to mobile site
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|ipad|iphone|ipod|iemobile|opera [NC]mobile|palmos|webos|googlebot-mobile) [NC]
RewriteCond %{HTTP_HOST} !mobile\.website\.com$ [NC]
RewriteRule ^(?!m/).*$ http://www.mobile.website.com%{REQUEST_URI} [L,R,NC]

如果仍然无效,请发布您的Apache access.logerror.log的匹配行。