【问题标题】:HTACCESS REDIRECT TO mobile site but need to exclude one directoryHTACCESS 重定向到移动站点但需要排除一个目录
【发布时间】: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


    【解决方案1】:

    根据您显示的规则,您能否尝试遵循。如果您正在寻找从 stats 开始的 uri,请按照以下规则将 FROM stats 更改为 ^/stats

    RewriteEngine ON
    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] 
    RewriteCond %{REQUEST_URI} !stats [NC]
    RewriteRule ^ http://m.website.co.uk%{REQUEST_URI} [R,L]
    

    【讨论】:

    • 请确保在测试您的网址之前清除浏览器缓存。
    猜你喜欢
    • 2014-02-23
    • 2011-03-27
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    相关资源
    最近更新 更多