I'm trying out a lot of PHP example projects. For most examples I need to setup a VirtualHost in the Apache config (httpd-vhosts.conf
) to get them working.
But sometimes I just want to copy or test a project, without going through the hassle of making another VirtualHost.
It would be nice if everything still works too when I try http://localhost/ProjectDir/
instead of http://ProjectDir/
In Phalcon I know how to fix the root directory, by changing the config or with setBaseUri
(), but this is a bit inconvenient to change every time. It would be nice if this could be done automatically somehow. (I do realize that in this way I can not use absolute URLs or links inside the HTML (starting with /) since that would mean the root folder of the Apache server then but this could be solved with an automatically configured prefix-variable).
How do other developers handle this situation, or do you really choose between a virtual host or
http://localhost/ProjectDir/
?Is there a way for a PHP script to detect if it's running in a virtual host or in a subdir of localhost?
UPDATE
Found out I could use $_SERVER['SERVER_NAME']
to determine if it's 'localhost' or something else. Not very elegant, but it's a sufficient solution, I guess.