开发者

mod rewrite (css/images)

im using the following to rewrite my urls:

RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.+)\.html$ /$1 开发者_StackOverflow社区[R=301,L]
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+)$ $1.html

the problem is this causes the css and images to not appear - is there a way that the rules can be excluded from folders like css and images folder so that the appear as they should instead of dead images and no css? thanks Angel xx


Best Practice:

include all css / images and js files with absolute path instead of relative path when you apply .htaccess for URL rewriting.


Try

RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !/(css|images|js)/
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

Substitute css|images|js by your folder names, separated by |

Hope this helps...


Put your complete domain in your css link:

<link rel="stylesheet" type="text/css" href="css/style.css" media="all" />

to

<link rel="stylesheet" type="text/css" href="http://www.yourdomain.com/css/style.css" media="all" />

When using rewrite url's you get directories: yoururl.com/dir/dir/item.html making the paths in your html to the css files incorrect.

If you want to avoid this it's best to use complete paths to your css files. Your browser doesn't understand you are rewriting url's so it thinks that you are just browsing trough directories.


You can change

<link rel="stylesheet" type="text/css" href="css/style.css" media="all" />

To

<link rel="stylesheet" type="text/css" href="/css/style.css" media="all" />

"/" as root directory on your hosting. Similar with "/image/...".

Hope this helps...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜