我希望这个网址:
http://www.example.com/path/antyhing
不被重定向。
下面就是我有没有工作:
的RewriteCond%{REQUEST_URI}!^ /路径/.*$ [NC]
重写规则^ http://m.example.com/ [R,L]
目前它重定向所有URL以 http://m.example.com/
下面是完整的code。在我的.htaccess文件:
的RewriteBase /
RewriteEngine叙述上
#检查手机= 1时,设置cookie的移动等于1
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 1(安培; | $)
重写规则^ - [CO =移动:1:%{HTTP_HOST}]
#检查手机= 0,并设置cookie的移动等于0
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 0(安培; | $)
重写规则^ - [CO =移动:0:%{HTTP_HOST}]
#跳过下一条规则,如果手机= 0
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 0(安培; | $)
重写规则^ - [S = 1]
#检查,这看起来像一个移动设备
的RewriteCond%{HTTP:X-WAP瞩目} ^ $ [OR]!
的RewriteCond%{HTTP_USER_AGENT}的Android |黑莓| ipad公司| iPhone | iPod的| iemobile | Opera移动| PalmOS的|的webOS | Googlebot的移动[NC,OR]
的RewriteCond%{HTTP:档案} ^ $!
#检查,如果我们不是已经在移动网站
的RewriteCond%{HTTP_HOST}!^ M 。
#检查以确保我们以前没有设置cookie
的RewriteCond%{HTTP:饼干}!移动= 0(; | $)
#不重定向路径页面
的RewriteCond%{REQUEST_URI}!^。+?/路径/.*$ [NC]
#现在重定向到移动网站
重写规则^ http://m.example.com/ [R,L]
解决方案
您可以用此取代你的最后一条规则:
选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /
#检查手机= 1时,设置cookie的移动等于1
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 1(安培; | $)
重写规则^ - [CO =移动:1:%{HTTP_HOST}]
#检查手机= 0,并设置cookie的移动等于0
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 0(安培; | $)
重写规则^ - [CO =移动:0:%{HTTP_HOST}]
#跳过下一条规则,如果手机= 0 [OR]如果它是一个文件[OR]如果/路径/
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 0(安培; | $)[OR]
的RewriteCond%{} REQUEST_FILENAME -f [OR]
的RewriteCond%{REQUEST_URI} ^ * /路径/.*$
重写规则^ - [S = 1]
#检查,这看起来像一个移动设备
的RewriteCond%{HTTP_PROFILE}!^ $ [OR]
的RewriteCond%{HTTP_X_WAP_PROFILE}!^ $ [OR]
的RewriteCond%{HTTP_USER_AGENT}的Android |黑莓| ipad公司| iPhone | iPod的| iemobile | Opera移动| PalmOS的|的webOS | Googlebot的移动[NC]
#检查,如果我们不是已经在移动网站
的RewriteCond%{HTTP_HOST}!^ M 。
#检查以确保我们以前没有设置cookie
的RewriteCond%{} HTTP_COOKIE手机!= 0(; | $)
#不重定向路径页面
的RewriteCond%{REQUEST_URI}!^ * /路径/.*$ [NC]
#现在重定向到移动网站
重写规则^ http://m.example.com/ [R,L,NC]
修改由OP:唯一的问题是从%{REQUEST_URI}未来
,对,我不明白只是工作的一个原因对 ^ * /路径/.*$
I want this URL:
http://www.example.com/path/antyhing
to NOT be redirected.
Here's what I have which is not working:
RewriteCond %{REQUEST_URI} !^/path/.*$ [NC]
RewriteRule ^ http://m.example.com/ [R,L]
Currently it redirects all URLs to http://m.example.com/
Here is the full code in my .htaccess file:
RewriteBase /
RewriteEngine On
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
# Skip next rule if mobile=0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [S=1]
# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie} !mobile=0(;|$)
# Don't redirect "path" pages
RewriteCond %{REQUEST_URI} !^.+?/path/.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^ http://m.example.com/ [R,L]
解决方案
Can you replace your last rule with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
# Skip next rule if mobile=0 [OR] if it's a file [OR] if /path/
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_URI} ^.*/path/.*$
RewriteRule ^ - [S=1]
# Check if this looks like a mobile device
RewriteCond %{HTTP_PROFILE} !^$ [OR]
RewriteCond %{HTTP_X_WAP_PROFILE} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE} !mobile=0(;|$)
# Don't redirect "path" pages
RewriteCond %{REQUEST_URI} !^.*/path/.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^ http://m.example.com/ [R,L,NC]
Edit by OP: The only problem was coming from the %{REQUEST_URI}
that for a reason that I don't understand only works against ^.*/path/.*$