.htaccess root changed with mod_rewrite

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


Source: .htaccess

1 Comment

  1. Digin Dominic

    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 section of your page’s HTML:

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

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.