Welcome to WebmasterWorld Guest from 54.225.2.178

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

base url

     
10:47 pm on Jul 8, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1541
votes: 0


Is there some way to keep links static for each page?

e.g. if I want to link to something like:
<a href="http://www.domain.com/<?php echo $row['url']' ?>

Is there some substitute I can use instead of domain.com?
12:10 am on July 9, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2003
posts:923
votes: 21


On most Apache-based servers, if you wanted to use complete URLs, you could use something like:

<a href="<?php echo $_SERVER['HTTP_HOST'] . '/' . $row['url']' ?>

If relative URLs are okay, you could simply use:

<a href="<?php echo '/' . $row['url']' ?>
4:04 pm on July 9, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


I'd go with the latter, and clarify, that means domain root relative, which will almost always work. Too often links are coded like so,

<a href="script.php">

Which is "just relative to wherever you are." This is fine if the resource is always "in the same directory." When you get to using rewrite rules and other conditions, it's not always the case. The leading slash always means "start at the domain root."

A bonus, that works whether you're currently on an SSL page or a non SSL page, subdomain, even a second site.

<a href="/script.php">

can be

http ://www.example.com/script.php
https ://example.com/script.php
http ://mysubdomain.example.com/script.php

http ://www.some-other-example.com/script.php
8:20 pm on July 9, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1541
votes: 0


Ok, so just insert a slash in before the url. Is that really enough? Rather than setting up a global variable.
4:00 pm on July 10, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


Yeah just that simple. :-)