2

I want to be able to use root-relative-paths (ex: /incl/file.php) while developing the website in XAMPP's localhost so that it will work in the same way when I upload it to a webserver. In order to do that, I've set up a Virtual Host within XAMPP. The Virtual Host works fine when I access it with absolute paths (ex: C:/xampp/htdocs/incl/file.php) or pahts without the slash (incl/file.php), but root-relative-paths (/incl/file.php) don't work at all.

I've tried many different configurations of Virtual Host set ups that I found here and on many websites and uninstalling and installing XAMPP. I've also tried to use "\" instead of "/", but the result is the same. I have Windows 10 Pro with the latest XAMPP version installed on it.

This is the Virtual Host set up I am currently employing.

In the hosts file:

# localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost
#   ::1             localhost
    127.0.0.1       atriero.localhost

In the httpf-vhosts.conf file:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
    <Directory  "C:/xampp/htdocs">
       Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "C:/xampp/subdomains/site"
    ServerName atriero.localhost
    <Directory  "C:/xampp/subdomains/site">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

As an example of root-relative-paths that are not working, in my index page I have

require "/header.php";

which is located on the "site" folder, the same where index.php is located. If I type "header.php" without the slash, it works fine.

There's also in the header.php page the following line

include_once '/includes/dbh.inc.php';

where the same issue happens, dbh.inc.php is located in the includes folder within the site folder. If I take the slash out the link works fine, but in the way it is writen, with root-relative-path, it doesn't work.

I expect that it is possible to run root-relative-paths with Virtual Host in XAMPP, I assume it would really help in the development of my website and as far as I know it would be the best way to do so.

If for some reason it isn't possible to use root-relative-paths with Virtual Host and if I have to upload my website to the server without the "\" before every path, will it be harmfull in any way to the working of my website?

Thanks in advance.

ArtH
  • 21
  • 1

0 Answers0