2014-01-10 24 views
1

我有一個名爲域example.com和移動版m.example.com其他子域的子域。 xxx.exmaple.com這我不希望使用的.htaccess當我重定向example.com重定向m.example.com,它也重定向xxx.example.comm.example。 COM的.htaccess .Redirecting除了一個子

我有以下代碼

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

回答

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] 
相關問題