Forum Moderators: Robert Charlton & goodroi
I do like absolute URLs like www.domain.com/folder/folder/ but I don't like to include the full domain every time.
I use a 301 redirect from non-www to www and then relative URLs counting from the root, which is sort-of the same as absolute, but only with reference within the domain: /folder/folder/.
I never include the filename when linking to an index page. I always end any links to folders with a trailing / to avoid the automatic server redirect that happens when you omit it.
Also because, you use PHP, you can easily set a session variable which will should use the ENV variable to get
$http_dir="YOUR.DOMAIN.COM";
// GET URL_ROOT
if(isset($_SESSION["url_root"])) //CHECK IF VAR EXIST
{$url_root=$_SESSION["url_root"];} else {$url_root="http://".$_SERVER['HTTP_HOST']."/".$http_dir."/";
session_register("url_root"); $_SESSION["url_root"]=$url_root;}
So that all my links look like :
echo "<a href='".$url_root."images/blah/blah/page.php'>";
This way, links works in any host/location. Just need to change the two lines in your include.
Hope this help!
I don't like relative URLs, ones that start ../../../etc.
I do like absolute URLs like www.domain.com/folder/folder/ but I don't like to include the full domain every time.I use a 301 redirect from non-www to www and then relative URLs counting from the root, which is sort-of the same as absolute, but only with reference within the domain: /folder/folder/.
I never include the filename when linking to an index page. I always end any links to folders with a trailing / to avoid the automatic server redirect that happens when you omit it.
I use nothing but relative addresses, as I can run the sites locally from the harddrive, and also place it on CD.
subst W: "[i]homepage local path[/i]"
I've heard that similar tricks are available on other platforms, but i don't know about them.
Hoping be useful,
Herenvardö
Images are all in img/ no matter in which directory they are used.
When testing a new site I can move it to example.com/sandbox and just need to change the base href tag and it works.
Once it is fully indexed, I generally drop the domain part of the URL, yet keep the absolute path.
I will only go with a relative path when the files actually belong together, and if I move them, they will be moved as a unit. For example if /greenwidget/part1/ links to /greenwidget/part2/ I will use "../part2/" in case I decide to move them both to /greenfuzzywidget/ at a later date.
In this case, a 404 error isn't handled properly - you can get to the custom page and then the navigation doesn't work.
And of course, I did exactly that - and when tested it, I of course typed a duff address like www.example.com/rubbish.html, and of course I was convinced the 404 page was working!
Having said all that, I still use relative links for the rest of the site.
DerekH