htaccess rewrite breaks relative paths
Add this line <BASE href="http://www.yoursitename.com/">
to your page inside the <head>
tag as the following:
<head>
<title>Your site title</title>
<BASE href="http://www.yoursitename.com/">
....
</head>
The problem is that you didn’t consider that relative URLs are resolved on the base URI that is the URI of the HTML document the reference is used in. So a relative URI path like assets/images/
in an HTML document with the URI path /home/
is resolved to /home/assets/images/
instead of /assets/images/
.
You cannot change this with mod_rewrite as URI resolution is done by the client and not by the server. The only solutions are:
- change the base URI using the
BASE
element (note that this affects all relative URI); - using absolute URI paths, e.g.
/assets/images/
instead of a relativeassets/images/
; - adjusting the relative URI path, so references in
/home/
are adjusted to../assets/images/
to reflect the path depth.