Web Hosting Talk







View Full Version : after mod-rewrite, all images file path screw up.


feelexit
06-06-2007, 10:38 AM
all my php files in theme folder, and images in images folder

http://localhost/theme/
http://localhost/theme/images

I use .htaccess rewrite my ugly url.
http://localhost/theme/category.php?type=movie
http://localhost/theme/category/movie

url works, but all the images in the category.php file cannot be displayed.

in the header.php file, I use <img src="images/logo.jpg">
now, after I rewrite the url, this image file cannot be found. cause, it try to find http://localhost/theme/category/images/logo.jpg
and category acutally does not exist.

I can change it to <img src="../images/logo.jpg">, but problem is header.php is the header file used for all other files.

index.php also use it,http://localhost/theme/index.php
if i change it to ../images/logo.jpg, then index.php couldnt find this image file.


is there a way to give the correct image path for all the files ?

sasha
06-06-2007, 10:52 AM
use base href

<base href="http://localhost/theme/" />

Then all your images have to be relative to that href.

yabsoft
06-07-2007, 12:26 PM
It is better to use absolute image url, i.e:/theme/images/logo.jpg.

and you can make the path conconfiguable if you want to chnage the directory that scripts resides in:

<img src="<?=$imagepath?>/images/logo.jpg">

Then define $imagepath in your header.php.

mwatkins
06-07-2007, 12:43 PM
You have a fixed path to images; use an absolute path to them. Since you are rewriting part of that path, you need to NOT rewrite any URL which refers to an image.

Use ReWriteCond to skip rewriting paths that include /images. Doing this from memory but believe this to be correct - insert this just before your RewriteRule(s):

RewriteCond %(REQUEST_URI) !^/theme/images(.*|)$ [NC]