移动URL重定向

时间:2015-05-22 05:11:19

标签: php wordpress .htaccess mod-rewrite

我正在使用WordPress高级新闻主题网站。 我正在使用移动网站m.coupontales.com的子域名,并将此代码添加到.htaccess文件中:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^m\. [NC]
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera\smobile|palmos|webos) [NC]
RewriteRule ^ http://www.coupontales.com%{REQUEST_URI} [L,R=302]

但作为网站管理员,当我转到m.coupontales.com/wp-admin时,它会重定向到www.coupontales.com。如何阻止我的访问?

1 个答案:

答案 0 :(得分:0)

RewriteEngine On

# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]

# 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}       !^$
# 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}        !\smredir=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.example.org%{REQUEST_URI} [R,L]

请点击此链接 Mobile Redirect using htaccess