【发布时间】:2021-04-27 16:48:45
【问题描述】:
我使用下面的 htaccess 代码将移动设备上的任何人重定向到网站的移动版本,但我需要排除文件夹统计信息 我该怎么做呢
RewriteBase /
# Check if this is the m=no query string
RewriteCond %{QUERY_STRING} (^|&)m=no(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]
# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-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,OR]
RewriteCond %{HTTP:Profile} !^$
#Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} ^(?:www\.)?website\.co.uk$
#Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=no(&|$)
#Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
#Now redirect to the mobile site
RewriteCond %{REQUEST_URI} !\.(?:gif|jpe?g|png|pdf)$ [NC]
RewriteRule ^ http://m.website.co.uk%{REQUEST_URI} [R,L]
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting