问题
I am trying to make an .htaccess file, to create SEO url.
It seems however that I can't have a slash in the mod rewrite, am I doing this wrong?
My code is as follows:
RewriteEngine on
RewriteRule ^(.+)/$ /$1 [L,R=301]
RewriteRule ^folder/folder-name index.php?show=folder&folder_id=7
The page is loaded correctly, but the style sheet/images/javascript aren't found!
It's as if, the page thinks that it should look for the style/images/js relative to "folder/folder-name".
If i change the last line to:
RewriteRule ^folder-folder-name index.php?show=folder&folder_id=7
Then everything is loaded correctly, so i'm pretty sure it's because of the slash.
Any help?
回答1:
It is because you're using relative paths in your JS, CSS etc. You have 2 options to fix it:
- Just use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with
http://
or a slash/
. You can try adding this tag in your page's header:
<base href="/" />
回答2:
One alternative: You can use paths relative to site root. i.e. change:
<img src="images/some.jpg" />
by
<img src="/images/some.jpg" />
Being images folder here: yoursite.com/images
来源:https://stackoverflow.com/questions/20616831/why-cant-i-have-slashes-in-my-rewrite-rule