使用完整站点链接重定向到移动站点

时间:2013-11-08 17:12:45

标签: regex apache .htaccess mod-rewrite mobile

我正在为移动用户设置重定向到移动登录页面,而我正在使用的脚本正在甩掉505.

整个htaccess代码如下:(更新)

<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</IfModule>
</FilesMatch>

#MobileSetup
RewriteEngine On 
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ – [CO=mredir:0:http://www.maindomain.com]

RewriteCond %{HTTP_HOST} !^http://www.maindomain.com/mobile/\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpg|css|png|gif)$ [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera         mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) [NC]
RewriteCond %{HTTP_COOKIE}  !mredir=0 [NC]
RewriteRule ^ http://www.maindomain.com/mobile/? [R,L]

#Was at the top

RewriteEngine On 
RewriteBase /

RewriteRule ^news/([a-zA-Z0-9_-]+)$ /news.php?url=$1 [NC,L]

RewriteCond %{HTTP_HOST} ^maindomain.com$
RewriteRule ^(.*)$ http://www.maindomain.com$1 [R=301,L]

ErrorDocument 404 /404.php

#Redirects
Redirect 301 main site redirects

#10.28.13
Redirect 301 main site redirects

我试过调试这个但无济于事。服务器上设置了重定向,强制非www。转到 www。
这会引起问题吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

你可以尝试:

RewriteEngine On 

RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ – [CO=mredir:0:http://www.regularsite.com]

RewriteCond %{HTTP_HOST} !^mobile-site\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpg|css|png|gif)$ [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) [NC]
RewriteCond %{HTTP_COOKIE}  !mredir=0 [NC]
RewriteRule ^ http://mobile-site.com/? [R,L]

更新::您的完整.htaccess:

RewriteEngine On 
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ – [CO=mredir:0:http://www.maindomain.com]

RewriteCond %{REQUEST_URI} !\.(jpg|css|png|gif)$ [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) [NC]
RewriteCond %{HTTP_COOKIE} !mredir=0 [NC]
RewriteRule !^mobile/ /mobile/? [R,L]

RewriteCond %{HTTP_HOST} ^maindomain.com$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^news/([\w-]+)$ /news.php?url=$1 [NC,L,QSA]