.htaccess重定向301 - 无法从移动目录加载文件

时间:2015-01-27 16:34:04

标签: regex apache .htaccess mod-rewrite mobile

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|ipad|iemobile" [NC]
RewriteRule ^((?!m/).*)$ /m/$1 [R=301,L]

这就是我的网络服务器根目录中的.htaccess的样子。 它成功重定向到/ m但它不会从我的根目录加载文件。我在我的移动目录中使用../js和../css从它的父目录加载这些文件。 / m文件夹还没有.htaccess。

1 个答案:

答案 0 :(得分:0)

从规则中排除文件和目录:

RewriteEngine On

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|ipad|iemobile" [NC]
RewriteRule ^((?!m/).*)$ /m/$1 [R=302,NE,NC,L]

您也可以尝试在页面的HTML部分中添加:

<base href="/" />

以便从该网址解析每个相对网址,而不是当前网页的网址。