Re: absolute vs relative path?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 25 Jan 2006 at 15:19, William Stokes wrote:

> Hello,
> 
> I Have a web site on one server and a test site on another. How can I build 
> the hyperlinks so that they work on both servers without modification.
> 
> For example build this link dynamically:
> "http://www.domain.com/www/test.php
> 
> In test server the same should be:
> "http://internalserver/www/test.php

Non-php solution:

Use relative links. Instead of referring to a page as 
"http://www.domain.com/www/test.php";, rather just use 
"/www/test.php" or even just "/test.php", if the script containing 
that link is already in /www. Thus your links will look the same on 
both versions.

php-based solution:

If you must have absolute URLs (maybe to do redirects or SSL) use:
$_SERVER["SERVER_NAME"]
it will return either "www.domain.com" or "internalserver". So you 
can build your links as:

<?php
$url = 'http://' . $_SERVER["SERVER_NAME"] . '/www/test.php';
?>

Geoff.

> 
> Thanks
> -Will 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux