views:

118

answers:

1

Just started a site and I have an /img directory on the main domain. I would like to set up a subdomain(where the file folder is just another one in the main directory) that is able to use the /img folder but it doesn't work.

The /img and /subdomain folders are on the same level, so to display images in the main domain I type: <img src="img/image.jpg"> and for the /subdomain I type: <img src="../img/image.jpg"> and I get a 404 error for the site: http://subdomain.example.com/img/image.jpg As you can see, I want it to be linking to http://www.example.com/img/image.jpg

Can anyone tell me how to achieve this? I would prefer not to link images to their internet directory (i.e. http://www...) because I would like to modify the sites on my computer and upload them via ftp.

I'm sure it's just something that I am messing up or don't completely understand. Thanks in advance!

+1  A: 

Relative paths are always relative to a URI. If you have a page at http://subdomain.example.com/ containing a link to ../img/image.jpg, the web server translates it into a link to http://subdomain.example.com/../img/image.jpg. Obviously the web server can't serve anything above it's root directory (that's the whole point of having a root).

Your webserver is configured to only serve content in the /subdomain directory, but obviously /img is not inside that directory, and can't thus be served. What you need to do is configure your webserver to look in /img (the directory on your filesystem) instead of /subdomain/img when it gets an request for any content at http://subdomain.example.com/img/

With Apache this can be done with mod_alias.

Summary: Use mod_alias to map requests to http://subdomain.example.com/img/ to the directory /img.

pafcu