We are new to mod_rewrite and semantic URLs and despite researching Google and SO we have not been able to find a clear answer to this question.
When we use a forward slash as a seperator in our .htaccess, all of our image, css and js references in our html have to be rewritten from relative paths to absolute paths.
For example:
RewriteRule ^([A-Za-z0-9-]+)/?$ inhalt.php?ebene1=$1 [NC,L] # process ebene1
RewriteRule ^([A-Za-z0-9-]+)\/([A-Za-z0-9-]+)/?$ inhalt.php?ebene1=$1&ebene2=$2 [NC,L] # process ebene1,2
RewriteRule ^([A-Za-z0-9-]+)\/([A-Za-z0-9-]+)\/([A-Za-z0-9-]+)/?$ inhalt.php?ebene1=$1&ebene2=$2&ebene3=$3 [NC,L] # process ebene1,2,3
means having to rewrite:
<link href="css/acssfile.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/ajsfile.js"></script>
<img src="imgs/animage file.gif" alt="" />
to:
<link href="http://www.oursite.com/css/acssfile.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://www.oursite.com/js/ajsfile.js"></script>
<img src="http://www.oursite.com/imgs/animage file.gif" alt="" />
Is this always a consequence of using forward slashes as seperators in semantic URLs, or is there a way to keep our relative paths?
You could probably keep your paths to resources relative to the root of your site :
/css/acssfile.css
, that way you don't have to care about the path of the actual page being displayed...The browser is resolving those CSS includes relative to the URL it's on. If your URLs change from
inhalt.php
tofoobar/
, then the browser is now in a different path. While it was on/inhalt.php
, the relative pathcss/acssfile.css
resolves to/css/acssfile.css
. However, when it's on/foobar/
, that relative path resolves to/foobar/css/acssfile.css
.It's a good idea to use absolute paths, but not absolute URLs including the domain. So, link to your asset files as: