简体   繁体   English

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

[英].htaccess Redirect 301 - can't load files from mobile directory

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

This is how the .htaccess in the my webserver's root looks like. 这就是我Web服务器根目录中的.htaccess的样子。 It redirects successfully to /m but it won't load files from my root directory. 它成功重定向到/ m,但不会从我的根目录加载文件。 I use ../js and ../css in my mobile directory to load such files from it's parent directory. 我在移动目录中使用../js和../css从其父目录加载此类文件。 The /m folder doesn't have an .htaccess yet. / m文件夹尚没有.htaccess。

Exclude files and directories from your rule: 从规则中排除文件和目录:

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]

You can also try adding this in the section of your page's HTML: 您也可以尝试在页面的HTML部分中添加以下内容:

<base href="/" />

so that every relative URL is resolved from that URL and not the current page's URL. 以便从该URL而不是当前页面的URL解析每个相对URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM