Forum Moderators: phranque
I would like some help regarding a .htaccess rule.
What i am trying to do:
Let's suppose that my site is:
http://www.example.com
And a url which shows something is:
http://www.example.com/show.php?id=12&name=cars
What i try to do is:
RewriteRule ^viewing/([0-9]+)(.+)/?$ ./show.php?id=$1&name=$2 The above works correctly,but the problem is that the page loads without .css,images etc
(It is set that the path to .css is eg ./template/mysitetheme/style.css)
The Same happens with links:
Eg the link to the homepage becomes: http://www.example.com/viewing/ instead of http://www.example.com (as the url-link to the homepage is:
<a href="./index.php"/>homepage</a>) Thanks in advance!
[edited by: jdMorgan at 1:59 am (utc) on May 21, 2009]
[edit reason] example.com [/edit]
This is the most likely reason for your trouble. It is due to the fact that it is the client (e.g. browser) that resolves relative links. For page-relative links like <img src="images/logo.gif">, it does so based on the current page's 'directory' which is shown in the address bar.
So, if you are viewing a page at http://www.example.com/viewing/12-cars.html and that page includes an image link of <img src="images/logo.gif">, then the browser will remove "12-cars.html" and add "images.logo.gif", to get a canonical URL of "http://www.example.com/viewing/images/logo.gif". Since "/viewing" is not a 'real' directory, the image path is therefore wrong.
Adding the leading slash to the <img src> path causes the browser to remove all path information and add the specified URL-path to the domain's root, yielding the correct image URL of "http://www.example.com/images/logo.gif".
You can easily confirm this problem by looking at your server error log and access log files. The "Live HTTP Headers" add-on for Mozilla/Firefox browsers also comes in handy for debugging these problems. It's basic Webmaster kit.
Jim