.htaccess root changed with mod_rewrite

32 views Asked by At

So i'm trying to rewrite the URL like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?page=$1 [QSA]

Works perfectly but relative paths to JavaScript and CSS get messed up.

Shouldn't the line below exclude files ?

  RewriteCond %{REQUEST_FILENAME} !-f
1

There are 1 answers

0
anubhava On BEST ANSWER

RewriteCond %{REQUEST_FILENAME} !-f makes sure existing files are not rewritten hence images/css/js files won't be routed to index.php.

However your problem seems to be use of relative paths for images/css/js. Make sure to 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 /.

Otherwise you can add this in the <head> section of your page's HTML:

<base href="/" />

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