Welcome to WebmasterWorld Guest from 54.162.157.136

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

base url

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

WebmasterWorld Senior Member 10+ Year Member



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 Jul 9, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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 Jul 9, 2012 (gmt 0)

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



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 Jul 9, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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 Jul 10, 2012 (gmt 0)

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



Yeah just that simple. :-)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month