简体   繁体   中英

.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. It redirects successfully to /m but it won't load files from my root directory. I use ../js and ../css in my mobile directory to load such files from it's parent directory. The /m folder doesn't have an .htaccess yet.

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:

<base href="/" />

so that every relative URL is resolved from that URL and not the current page's URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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