Relative paths break in HTML when using mod_rewrite in .htaccess
I am new to .htaccess
and mod_rewrite.
I am using the following rewrite rules:
RewriteRule ^wants/([0-9]+)$ /wantlist.php?wantid=$1 RewriteRule ^dashboard$ /dashboard.php
I can successfully redirect both cases.
But to do this, I had to change CSS, JS and other paths to absolute paths, without which CSS and JS would not load.
I used
<script type="javascript" src="js/javascript.js"></script>
which after the rewrite rule didn't work, and after I changed it to
<script type="javascript" src="http://example.com/js/javascript.js"></script>
I got this to work.
The same happens with any other URL on the site.
Is there a way to get around this since I use relative paths pretty much everywhere on a site I am developing?
0
a source to share
1 answer
This is a URL resolution issue. See mod_rewrite url required
You can explicitly set the base URI from the BASE
HTML element , for example:
<base href="/">
0
a source to share