我正在使用小型CMS,我通过RewriteRule
中的htaccess
将所有原始目录更改为我想要的目录,同时为移动设备用户添加移动模板。所以我的网站有两个目录,一个用于计算机客户端,一个用于移动客户端,我使用以下代码检测移动代理并重定向到移动模板但是出现循环错误,任何想法!?
这是我的重定向代码:
RewriteCond %{REQUEST_URI} !^/m/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]
这是我目前的htaccess:
Options +FollowSymLinks
RewriteEngine On
# Change main URL
RewriteRule ^m/ /mobile/index.php [QSA]
# Change content URL
RewriteRule ^/a/m/([a-zA-Z0-9\.]+)$ /mobile/index.php?pid=$1 [QSA]
答案 0 :(得分:1)
您需要检查URI是否也不是重写的URI(/mobile/...
)。您可以通过查看%{THE_REQUEST}
或查看/mobile
:
RewriteCond %{THE_REQUEST} !\ /m/.*
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]
或:
RewriteCond %{REQUEST_URI} !^/a/m/.*$
RewriteCond %{REQUEST_URI} !^/m/.*$
RewriteCond %{REQUEST_URI} !^/mobile/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]