View Full Version : Subdomains and Relative Paths

11-04-2004, 01:40 AM
I see several threads on subdomains, but have come across nothing referring to this specific topic...

Let says that I have a subdomain called xxx.yyy.com and it is pointing to a directory /html/xxx. I now want to include an image that is in the folder above it. In order to do this in HTML, I would type something like:

<img src="../zzz.gif">

However, this does not seem to work. It works just fine if I call the page up like so:


Is there some known limitation on using relative paths with subdomains? If so, is there a way around it?

Thank you.

11-04-2004, 02:51 AM
I should also add to the above post that I can use images just fine for images that are within the xxx directory. This problem just seems to occur for images that require me to go "up" a directory.

11-04-2004, 05:51 AM
That is because when you set the domain xx.yy.zz.aa to point to the directory:
then that becomes the root of the site, so surfing to http://xx.yy.zz.aa/ will give you the files in the folder /var/www/html/xx/

You cannot set the URL to "../image.gif" because there is nothing *above* the root of the site!

11-04-2004, 06:32 AM
If you wanted to you could create a sym link in the second domain that points to the image directory in the main domain if you wanted to.

So if you had all the images you wanted to access in the main domain in /var/www/html/firstdomain/images/ then you would set the sym link on the seconddomain to point to that directory. You could then us src=/images/zz.gif in the second domain and it should work.

01-17-2005, 11:35 PM
Can you explain what a sym link is and how it works? I'm having the same problem. Sorry that I'm not familiar with that term.

Also... is this the best solution for this problem? Should I change all the paths to absolutes? Or include an 'images' folder inside the sub-domain folder too, even though it would duplicate the information already in the main /images folder? Or maybe something else? What do the 'big-boys' do when they use sub-domains?

Thanks for the help.

01-18-2005, 01:50 AM
A symlink is what I believe is called a shortcut in the Windows world and an alias in the Mac world. It is a very short file that 'points' to another file location.
So, if there is a file /var/www/html/images/round.gif
then we could create a symlink (or shortcut) at /var/www/htmlsub/images/round.gif that simply points to the other file. There is only one file in the system and changing the file will result in the changes showing up in both places.

It is not the best solution for the problem. The best solution is to create an alias for the two domains so that they point to a server path location. This is done in the httpd.conf file normally, but I think you can do this through Site Manager, in the Domain section under Aliases.

01-18-2005, 03:39 PM
I'm really close to following you, but not quite.

Can someone explain to me how I would/why I would create these aliases for the domains?

Does it matter one is a domain and the other a sub-domain of that domain?

01-18-2005, 07:19 PM
Go in to your Site Manager and click on Domain Management. Then click on Web Aliases. You should now see the sub domain you set up listed. Click on it. On the next screen you should see a button on the bottom that says "New Alias" click on it. Now in the pop up window you want to enter your info in the top two fields since you are setting up a regular Alias. Based on what you have said in other post you would enter something like this:
URL path (Alias path name): /images/
Absolute path name: /var/www/html/images/

Now in your second domain if you want an image that is in your main domains image directory all you should have to enter is <img src="/images/xxx.gif">.