Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 移动重定向和循环错误_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex 移动重定向和循环错误

Regex 移动重定向和循环错误,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我正在使用小型CMS,我通过htaccess中的RewriteRule将所有原始目录更改为我想要的目录,还为移动设备用户添加了移动模板。所以我的网站有两个目录,一个用于计算机客户端,一个用于移动客户端,我使用以下代码检测移动代理并重定向到移动模板,但出现循环错误,有什么想法吗 这是我的重定向代码: RewriteCond %{REQUEST_URI} !^/m/.*$ RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|i

我正在使用小型CMS,我通过
htaccess
中的
RewriteRule
将所有原始目录更改为我想要的目录,还为移动设备用户添加了移动模板。所以我的网站有两个目录,一个用于计算机客户端,一个用于移动客户端,我使用以下代码检测移动代理并重定向到移动模板,但出现循环错误,有什么想法吗

这是我的重定向代码:

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]
这是我当前的访问权限:

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]

您需要检查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}中删除斜杠^m/*$@V.Melnychuk我试过了,但没有成功@AliGhanei这是因为相对URI基已更改(从
/
/mobile
更改为
/m/
/a/m/
)。您需要使用绝对URL,或者在页面标题中包含一个
。为什么在我使用绝对URL时此代码会阻止我的其他链接?@alighani是否有图像、脚本等资源不应重定向到
/m/
/mobile/
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]