Forum Moderators: coopster
Is there a piece of code that can be put a the top of a page, that would make all links relative to the root directory instead of the current directory?
basically when i put
<?php include"head.php"?>
this would also have to change a href inside head.php, which would usually link to myurl.com/dir1/page2.php
to link to myurl.com/page2.php
cheers
[edited by: Olly333 at 8:40 am (utc) on May 11, 2009]
<?php include($_SERVER['DOCUMENT_ROOT'].'/head.php'); ?>
Or, you could consider adding the webroot to your include_path, so you would not need to explicitly state the path to your included files each time.
...but will that for example, because the actual file is in a sub dir, will it change the style.css call in the header.php to ../style.css?
Ah, yes that could be a problem if head.php includes relative links to your stylesheet(s) and head.php is being included into pages at different depths in your directory tree.
As g1smd suggests, you should be able to use root-relative links to your stylesheets, by preceeding your URL with a single slash, ie:
href="/styles/style.css" By using root-relative links in this way will mean that all links use the same path regardless of where the file is located in the directory tree.