【问题标题】:.htaccess .Redirecting Except a Subdomain.htaccess .Redirecting 子域除外
【发布时间】:2014-01-29 18:29:48
【问题描述】:

我有一个名为 example.com 的域和一个移动版本的子域 m.example.com另一个子域。我不想重定向的 xxx.exmaple.com 当我将 example.com 重定向到 m.example.com 时使用 .htaccess,它也将 xxx.example.com 重定向到 m.example.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]

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect mobile


    【解决方案1】:

    在下面添加此条件以代替:RewriteCond %{HTTP_HOST} !^m\.

    RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$
    

    你的最后一条规则是:

    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\.)?example\.com$
    # 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]
    

    【讨论】:

      猜你喜欢
      • 2012-06-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 2014-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      相关资源
      最近更新 更多