Click to See Complete Forum and Search --> : Path To Scripts & Images On Apache


chestertb
11-08-2006, 08:01 AM
Hi All,

I have a bit of an odd question, so if this is not the right place to ask it, then my apologies.

My site is hosted on an apache server. I want to set up a subdomain that accesses scripts in the top level domain.

Apache sets up the site with a public_html folder. domain.com would have its index file in the public_html folder.

The path to that public_htlm folder would be "/home/username/public_html/". Therefore, to access a file in the admin folder in public_html, the path would be "/home/username/public_html/admin/".

When Apache creates a subdomain, say www.test.domain.com, it creates a folder (test) in public_html. Curiously, the path to admin works from the subdomain for "/home/username/public_html/admin/connect.inc.php", but it doesn't work for scripts or images.

I'm stumped, and my hosting provider doesn't provide support for scripting.

Any clues?

bokeh
11-08-2006, 09:41 AM
You are confusing two things: file paths and URLs. In the case of URLs in order for things to work in relation to one another the document and its images must be descendants of a common root directory. In the case of http://domain.com/sub/file.ext that is the case. The root directory is marked in red./home/username/public_html/sub/file.ext
/home/username/public_html/images/image.jpg in the case of http://lemon.domain.com/file.ext things are like this:/home/username/public_html/lemon/file.ext
/home/username/public_html/images/image.jpgIn this case the files do not share a common root directory so the only way to get things to work is use a full, absolute URL to call the image file from the document.

chestertb
11-08-2006, 04:19 PM
So even though, on the server's hard drive, test is a subfolder of public_html, there's still no way I can path to files in that folder, other than by using the url (which won't work because it's the scripts I want to access, not the images.

Hmmm... ah well, back to the drawing board. Thanks Bokeh.

bokeh
11-08-2006, 04:33 PM
So even though, on the server's hard drive, test is a subfolder of public_html, there's still no way I can path to files in that folder, other than by using the url (which won't work because it's the scripts I want to access, not the images.Of course you can do it with a file path. What you can't do is use relative URLs in the document.

chestertb
11-09-2006, 05:39 AM
Ok. I get it.

This works...
// get the connection variables
require_once '/home/user/public_html/admin/connect.inc.php';
$user = $connect[0];
$pass = $connect[1];
$db = $connect[2];
...because it's a file path.

This doesn't...
<a href='/home/user/public_html/admin/setup.php'>
...because it's a url.

So is the no way to path to the setup.php script?

Taschen
11-09-2006, 06:50 AM
Just to clarify:

A relative URL looks like this <a href="../directory/file.html">link</a>

A fully qualified URL looks like this <a href="http://www.domain.tld/directory/file.html">link</a>

With a fully qualified url the server can resolve the true location of a file. When using subdomains and relative URLs the server can't accurately resolve the file location because the relative URL points to the wrong directory in this example the "htpdocs" root, whereas it should be looking in "htpdocs/subdomaindirectory/":

sub domain url - htt://subdomain.mydomain.tld/file.html
actual file location htt://mydomain.tld/subdomaindirectory/file.html

Hope this helps. I would also counsel against putting this "/home/user/public_html/admin/setup.php" in a link or to locate an image file, rather use a fully qualified URL. You are giving away more than you want to about your server setup.