my .htaccess file looks like:
RewriteEngine On
RewriteRule ^([^/]*)$ index.php/?node=$1 [L]
now when I include my css file with:
<link href="sitewide.css" rel="stylesheet" type="text/css" />
it doesn't work. The same goes for javascript.
I've been looking everywhere for an easy solution that wouldn't make me hardcode baselinks for all my relative paths, like imgs, css, javascript...
So here it goes, add this between the <head>
tags of the pages you are having problems:
<base href='http://www.mydomain.com/'>
This will make that your relative path links will start with this base link. Simple as that.
The <base>
tag specifies the base URL/target for all relative URLs in a document. Put the <base>
tag as the first element inside the <head>
element, so that other elements in the head section uses the information from the <base>
element.
Did it work for you?
Consider rewriting only non-existing paths, e.g. if file or directory exists - don't rewrite it.
Wordpress uses this to rewrite their permalinks, I think it's pretty good example:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
As you can see they have rewrite conditions to exclude existing files/directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With