One code on dev server, and production server - how to deal with links?

Posted by Yegor on Stack Overflow See other posts from Stack Overflow or by Yegor
Published on 2010-06-01T16:00:01Z Indexed on 2010/06/01 16:03 UTC
Read the original article Hit count: 161

Filed under:
|

I have a copy of a code running ont he prod server, and I sue my local machine(s) running xampp as a dev server. I have several websites that I actively develop, so Im forced to use http://localhost/sitename

All my URLs are relative to the domain, (/file.php). They work fine on the prod server, but on a local server, they all point to localhost, when I want to make them all work relative to the site folder they are in. Is there anything I could do, other than what I do now, which is this:

if($_SERVER['SERVER_NAME'] == "localhost") {
 $path_to = "http://" . $_SERVER['SERVER_NAME'] . "/folder";
 $path_to_files = $_SERVER['DOCUMENT_ROOT'] . "/folder";
} else {
 $path_to = "http://" . $_SERVER['SERVER_NAME'];
 $path_to_files = $_SERVER['DOCUMENT_ROOT'];
}

and simply putting $path_to before each link on the site.

© Stack Overflow or respective owner

Related posts about php

Related posts about paths