首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >移动URL重定向

移动URL重定向
EN

Stack Overflow用户
提问于 2015-05-22 13:11:19
回答 1查看 56关注 0票数 1

我使用的是WordPress高级新闻主题网站。我正在使用移动网站m.coupontales.com的一个子域,并在.htaccess文件中添加了以下代码:

代码语言:javascript
复制
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。我如何阻止我的访问?

EN

回答 1

Stack Overflow用户

发布于 2015-05-22 13:43:29

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30388776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档