Free localhost virtual domain on Windows OS

To use a virtual domain like on a Windows operating system and the application XAMPP or other website server for Windows operating system do the following:

In the path of your Windows operating system:  C:\Windows\System32\drivers\etc   there you can find the file called: host
Add the following to that file host:

# localhost XAMPP virtual domain:

# localhost XAMPP virtual domain:

In the root path of your XAMPP website  C:\xampp\htdocs  add the following script inside an new index.php file:

        //    Local host virtual domain script
        if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
            $uri = 'https://';
        } else {
            $uri = 'http://';
        $uri .= $_SERVER['HTTP_HOST'];
        //    header('Location: '.$uri.'/dashboard/');
        ### See "C:\Windows\System32\drivers\etc\hosts" file for the virtual domains like below.
        #    In host file by example:
        # localhost XAMPP Virtual Domain
        if(isset($_SERVER['HTTP_HOST']) and $_SERVER['HTTP_HOST'] == "" or $_SERVER['HTTP_HOST'] == ""){
            header('Location: '.$uri.'/website1/');    //    C:\xampp\htdocs\website1
        }elseif(isset($_SERVER['HTTP_HOST']) and $_SERVER['HTTP_HOST'] == "" or $_SERVER['HTTP_HOST'] == "")
            header('Location: '.$uri.'/website2/');    //    C:\xampp\htdocs\website2
            header('Location: '.$uri.'/home/');
Something is wrong with the XAMPP installation :-(

Assume /website1/ and /website2/ in the example index.php file above is the directory of your websites.
You can use the localhost virtual domain even when you are disconnected from the Internet.

Remember the virtual domain may not exists on the Internet when you are connected to the Internet, if it exists on the Internet and want to use your virtual domain, disconnect the Internet connection and load your virtual domain like a normal registered domain on the Internet in your website browser. 


. . .