You must be careful about the distinction between filesystem paths and the path component of a URI.
Quote:
Quoting grandpafred:
|
I'm not sure this is quite right.
www.domain.com/includes/mainmenu.php suggests you are thinking of this as having a URL, but this is just a file on the filesystem, included by PHP. It might be accessible at that URL, or it might not; there's no reason for it to be accessible by HTTP at all, and steps are often taken to prevent direct HTTP access to files that are intended only to be included.
Quote:
and since the menu items are in the root mainmenu.php is written with links like this:
a href="page.php"
He now wants to create some nested directories like this:
www.domain.com/sub/sub/page.php and use base href on that page to handle the mainmenu which I thought would work based on my having done that with ASP. However, this is not the case.... I get nasty php errors.
|
There's no need for <base>, just rewrite those links as <a href="/page.php">.
Quote:
I set the base href to http://www.domain.com and the page has no problem with using the style sheet which is accessed by
href="/includes/page.css"
|
That will work with or without <base> because the leading slash specifies that this is an absolute path.
Quote:
BUT has a problem with the mainmenu which is trying to be accessed like this:
<?php include("/includes/mainmenu.php") ?>
|
That's because that's a filename, not a URI path component, and it's handled by PHP on the server side, not by the browser, so <base> has no effect. The filesystem knows nothing of the structure of your URI space. Unless you actually have a file at /includes/mainmenu.php on your filesystem that won't work.
Quote:
|
I've tried putting a trailing slash / in the base href and removing the leading slash everywhere else... I've tried leaving the base href alone and adding a preceeding slash to the mainmenu links but can't get any combination to work.
|
Don't use <base>. The purpose of <base> is to deal with relative URIs in documents that are not served over HTTP. As long as you are serving your document over HTTP, your relative links will already be evaluated in the context of the URI of your page, and <base> buys you nothing.
Your PHP include() statements are something else altogether, you need to make sure the path is the correct filesystem path relative to the current directory on the filesystem. So you probably need to use something like:
Code:
include("../includes/mainmenu.php");
Quote:
|
I would suppose I could always suggest putting the absolute path in the mainmenu.php file but I am curious as to why the base href idea isn't working.
|
You should do that, the only way <base> can prevent you from needing to use absolute paths there would be if you put a URI in <base> that is different from the URI of the page, which would be incorrect.