Reputation: 11
im using the following to rewrite my urls:
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.+)\.html$ /$1 [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
Upvotes: 1
Views: 7962
Reputation: 1
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...
Upvotes: 0
Reputation: 54032
Best Practice:
include all css / images and js files with
absolute path instead of relative path when you apply .htaccess
for URL rewriting.
Upvotes: 6
Reputation: 20492
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...
Upvotes: 4
Reputation: 10340
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.
Upvotes: 1