【问题标题】:how to stop redirection for sub-domain using .htaccess如何使用 .htaccess 停止对子域的重定向
【发布时间】:2017-09-21 07:45:04
【问题描述】:

我的网站有两个不同的版本 一个用于桌面,第二个用于移动。 因此在 .htaccess 文件中,我在下面放置了代码,如果有人从手机进入我的网站,那么他/她将重定向到类似的手机版本 m.example.com 但是

我的问题是我也有一个子域。当有人尝试访问我的子域时,例如这个 blog.example.com,所以我的 .htaccess 正在检查他是否试图从移动设备访问我的子域,因此他将他重定向到我的移动版本。这是我不想要的。我希望重定向代码仅适用于我的前域而不适用于子域。

请帮助某人。

.htaccess

RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]

# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\.
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 

# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]

# Now redirect to the mobile site
RewriteRule ^ http://m.example.com [R,L]

#redirect mobile ends here

【问题讨论】:

    标签: php apache .htaccess redirect


    【解决方案1】:
    # Check if we're not already on the mobile site
    RewriteCond %{HTTP_HOST}          !^m\.
    

    这仅在子域 m 上不存在时才检查重定向。您也可以添加一条与其完全相同的规则来阻止博客。

    # Check if we're trying to reach the blog
    RewriteCond %{HTTP_HOST}          !^blog\.
    

    【讨论】:

    • 非常感谢
    猜你喜欢
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 2015-06-05
    • 2017-08-24
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多