I have a copy of a code running on the production server, and I use my local machine(s) running xampp as a dev server. I have several websites that I actively develop, so I’m 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.
You should use a vhost instead.
So, in your hosts file, add something like:
sitename.dev 127.0.0.1Then in
xampp/apache/conf/extra/httpd-vhosts.conf:Restart Apache then browse to http://sitename.dev
This should provide the same behavior as production.
Read more about vhosts here.