使用htaccess的重定向网站手机版网站网站、重定向、手机、htaccess

2023-09-02 11:27:44 作者:无所畏惧。

您好,我使用了下列code重定向到移动website.It工作正常,从移动到移动网站,domain.com到m.domain.com移动,而是?ID = 9结尾URL的即将到来。如何删除

 ?ID = 9
 

从URL。而如何重定向移动网站m.domain.com从桌面浏览器到domain.com。下面code只重定向的网站,从移动到移动网站m.domain.com

 #检查手机= 1时,设置cookie的移动等于1
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 1(安培; | $)
重写规则^  -  [CO =移动:1:%{HTTP_HOST}]

#检查手机= 0,并设置cookie的移动等于0
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 0(安培; | $)
重写规则^  -  [CO =移动:0:%{HTTP_HOST}]

#饼干不能设置和读取在同一个请求,以便检查
的RewriteCond%{QUERY_STRING}(^ |&安培;)移动= 0(安培; | $)
重写规则^  -  [S = 1]

#检查,这看起来像一个移动设备
的RewriteCond%{HTTP:X-WAP瞩目} ^ $ [OR]!
的RewriteCond%{HTTP_USER_AGENT}的Andr​​oid |黑莓| ipad公司| iPhone | iPod的| iemobile | Opera移动| PalmOS的|的webOS | Googlebot的移动[NC,OR]
的RewriteCond%{HTTP:档案} ^ $!

#检查,如果我们不是已经在移动网站
的RewriteCond%{HTTP_HOST}!^ M 。
#检查以确保我们以前没有设置cookie
的RewriteCond%{HTTP:饼干}!移动= 0(; | $)
#现在重定向到移动网站
重写规则^ HTTP://m.example.com% {REQUEST_URI} [R,L]
 

解决方案 301永久重定向对网站有什么好处 使用.Htaccess文件实现301重定向

要剥离的查询字符串追加 在这样的目标URL:

 重写规则^ HTTP://m.example.com% {REQUEST_URI}? [R,L]
 

HI i have used the following code to redirect to mobile website.It works fine from mobile to mobile website, domain.com to m.domain.com in mobile, but "?id=9" at the end of url is coming . How to remove the

 ?id=9 

from the url .And how to redirect the mobile webiste m.domain.com from desktop browser to domain.com . The below code only redirect the website from mobile to mobile webiste m.domain.com

# 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}]

# cookie can't be set and read in the same request so check
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(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]

解决方案

To strip query string append ? in the target URL like this:

RewriteRule ^ http://m.example.com%{REQUEST_URI}? [R,L]