2013-06-08 2 views
1

안녕하세요. 모바일 웹 사이트로 리디렉션 할 때 다음 코드를 사용했습니다. 모바일에서 모바일 웹 사이트 domain.com, 모바일의 m.domain.com까지 잘 작동하지만 "? id = 9 끝 "URL이오고있다.htaccess를 사용하여 웹 사이트를 모바일 버전 웹 사이트로 리디렉션

?id=9 

URL에서 제거하십시오. 모바일 웹 사이트 m.domain.com을 데스크톱 브라우저에서 domain.com으로 리디렉션하는 방법. 아래의 코드는 쿼리 문자열이 같은 대상 URL에 ?를 추가 제거하기 위해 모바일의 webiste의 m.domain.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] 
+2

가능하면하지 마십시오 . 대신 반응 형 웹 디자인을 사용하십시오. – PointedEars

+0

++ @PointedEars 미디어 쿼리와 함께 Moderniz j를 사용하여 장치가 모바일인지 알아보고 JS 및 CSS 파일의 조건부 동적로드를위한 YepNope js를 사용할 수 있습니다. 장치가 모바일 장치임을 감지하면 모바일 JS, CSS가로드됩니다. 그렇지 않으면 데스크탑 JS, CSS가로드됩니다. 이렇게하면 반응 형 디자인이됩니다. –

+0

@TolisEmmanouilidis Modernizr에는 클라이언트 측 스크립팅이 필요합니다. 클라이언트 측 스크립팅에 의존하지 않는 것이 좋습니다. 장치가 모바일 장치인지 알아낼 필요가 없습니다. 이러한 장치에서 문서를 올바르게 표시하려면 * 미디어 쿼리 (일반 CSS) 만 사용할 수 있습니다. 그런 다음 Geolocation API와 같은 특수 기능에 대한 지원 검색을 위해 스크립팅을 사용할 수 있습니다. 또 다시 Modernizr을 사용하지 않아도됩니다. – PointedEars

답변

1

모바일에서 웹 사이트 리디렉션 :

RewriteRule^http://m.example.com%{REQUEST_URI}? [R,L] 
+0

완벽하게 작동합니다. 감사합니다. –

+0

환영합니다. – anubhava

관련 문제