Images not working with root relative link
Posted: 04. March 2012 21:00
I recently installed XAMPP in order to test my PHP pages without uploading them. Localhost is up and running, all fine there.
The issue is that whenever I have an IMG tag, my image only displays with an absolute or relative SRC. However, I almost always use a leading "/" (src="/blah") so pages can be moved within the site and the images will remain intact. So essentially,
This WORKS:
or
This DOES NOT WORK:
I believe this is because my leading "/" is telling XAMPP to look in the htdocs folder, possibly? Is there something in the apache httpd.conf file I can edit to fix this issue? All images display fine if I open the local file with a browser (obviously, though, my PHP doesn't get parsed!). Images are fine when the site is online. Any ideas?
- joshua
The issue is that whenever I have an IMG tag, my image only displays with an absolute or relative SRC. However, I almost always use a leading "/" (src="/blah") so pages can be moved within the site and the images will remain intact. So essentially,
This WORKS:
- Code: Select all
<img alt="whatever" src="../imagefolder/mypic.jpg" />
or
- Code: Select all
<img alt="whatever" src="http://www.myurl.com/imagefolder/mypic.jpg" />
This DOES NOT WORK:
- Code: Select all
<img alt="whatever" src="/imagefolder/mypig.jpg" />
I believe this is because my leading "/" is telling XAMPP to look in the htdocs folder, possibly? Is there something in the apache httpd.conf file I can edit to fix this issue? All images display fine if I open the local file with a browser (obviously, though, my PHP doesn't get parsed!). Images are fine when the site is online. Any ideas?
- joshua