【发布时间】:2017-01-27 06:16:29
【问题描述】:
我的一个网站上的 .htaccess 文件有一些问题。
我得到的错误是我尝试重定向太多次。
它目前的工作方式是每次我在桌面上时都需要将 URL 重定向到子文件夹 /dist,如果我在移动设备上,我需要转到网站的移动版本而不是是以mobile.开头的子域
我的 htaccess 文件如下所示:
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.mywebsite.com/dist]
RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/www\.mywebsite\.com\/dist" [R=301,L]
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Can not read and write cookie in the 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://mobile.mywebsite.com [R,L]
有人可以帮忙吗?
这是我第一次尝试这样的事情
谢谢
【问题讨论】:
-
如果您也发布错误消息也会有所帮助。
-
加载资源失败:net::ERR_TOO_MANY_REDIRECTS
-
您的移动网站是否以
m.或mobile.开头? -
我已经设置了两个 m。和移动设备。
-
试试你的条件
RewriteCond %{HTTP_HOST} !^(m|mobile)\.[NC]`
标签: .htaccess redirect mod-rewrite