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
RewriteCond %{REQUEST_FILENAME} !-f
makes sure existing files are not rewritten hence images/css/js files won't be routed toindex.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:so that every relative URL is resolved from that base URL and not from the current page's URL.