2012-06-06 3 views
0

데스크톱 및 모바일 사이트가 있습니다. htaccess 파일에 다음과 같은 내용이 있습니다. 모바일 사이트에서 도메인의 기본 루트로 다시 리디렉션하려고 할 때 루프에 갇히게되어 다시 모바일로 연결됩니다. 사이트 폴더에 있습니다.htaccess 모바일 리디렉션

어떻게 이런 일을 막을 수 있습니까?

RewriteEngine On 
    RewriteCond %{HTTP_HOST} !^www.domain.co.uk$ [NC] 
    RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R,L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule (.*) /404.php [R=301,L] 
    RewriteCond %{THE_REQUEST} ^.*/index.php 
    RewriteRule ^(.*)index.php$ http://www.domain.co.uk/$1 [R=301,L] 
    ErrorDocument 404 /404.php 
    ExpiresActive On 
    ExpiresDefault "access plus 20000 seconds" 
    Header unset ETag 
    FileETag None 
    <IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase /domain-news/ 
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /domain-news/index.php [L] 
    </IfModule> 
    AddOutputFilterByType DEFLATE text/plain 
    AddOutputFilterByType DEFLATE text/html 
    AddOutputFilterByType DEFLATE text/xml 
    AddOutputFilterByType DEFLATE text/css 
    AddOutputFilterByType DEFLATE text/javascript 
    AddOutputFilterByType DEFLATE application/xml 
    AddOutputFilterByType DEFLATE application/xhtml+xml 
    AddOutputFilterByType DEFLATE application/rss+xml 
    AddOutputFilterByType DEFLATE application/javascript 
    AddOutputFilterByType DEFLATE application/x-javascript 

    RewriteEngine On 
    RewriteCond %{QUERY_STRING} ^file=(.+)$ 
    RewriteRule ^(.+)\.aspx$ $1.php?f=%1 

    RewriteEngine on 
    RewriteBase/
    # Check if this is the noredirect query string 
    RewriteCond %{QUERY_STRING} (^|&)m=0(&|$) 
    # Set a cookie, and skip the next rule 
    RewriteRule^- [CO=mredir:0:www.domain.co.uk] 

    # Check if this looks like a mobile device 
    # (You could add another [OR] to the second one and add in what you 
    # had to check, but I believe most mobile devices should send at 
    # least one of these headers) 
    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://www.domain.co.uk/m [R,L] 

답변

0

는 더 나은 방법이있을 수 있습니다하지만 난 사이트가 모바일 인 경우에 대한 조회 업을 꺼내 능숙하게 일했다

#mobile redirect 
RewriteCond %{REQUEST_URI} !^/m/.*$ 
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera|mobile|palmos|webos|googlebot-mobile" [NC] 
RewriteRule ^(.*)$ /m/$1 [R=301,L] 

을 넣어.