Search code examples
phpapachejoomlasubdomainvirtualhost

XAMPP Subdomain with Joomla Site


I'm using XAMPP v3.2.4 and I don't know if this makes any difference but Joomla 3.9.14

In my local environment I access my Joomla site by visiting localhost/mysite. I now want to have a sub domain localhost/apps.mysite.

I've created a folder called apps and placed this in my Joomla root directory, which is C:\xampp\htdocs\mysite\apps. This folder contains a single index.html file.

I've made the following changes;

In my Windows hosts file I added the following line;

127.0.0.1           localhost/apps.mysite

In my httpd-vhosts.conf file I added;

NameVirtualHost 127.0.0.1:80
<virtualhost *:80="">
    DocumentRoot "C:/xampp/htdocs/mysite/apps"
    ServerName localhost/apps.mysite
    ServerAlias www.apps.mysite.localhost.com
</virtualhost>

I haven't made any other changes to config files. I've restarted Apache a few times, no change.

When I visit the URL http://localhost/apps.mysite I see the following error;

Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404 localhost Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.3.9

What do I need to change in order to access my subdomain at http://localhost/apps.mysite


Solution

  • First host file does not handle folders, just map IP addresses to hostname.

    Host file should be

    127.0.0.1 localhost apps.mysite
    

    or

    127.0.0.1 localhost
    127.0.0.1 apps.mysite
    

    I prefer the second method because I can comment the line..

    Second Your virtual host ServerName localhost/apps.mysite does not work with sub folders.

    Valid Servername values can be: domain.com, example.com, site1.example.com, user.site1.example.com and son on.

    A virtual host example to map the apps.mysite should be:

    <VirtualHost *:80>
      ServerName apps.mysite
      ServerAlias  www.apps.mysite
      ## Vhost Document Root
      DocumentRoot "C:/xampp/htdocs/mysite/apps"
    </VirtualHost>
    
    

    This is a minimal example, no logs defined or directory specific rules. With this configuration you will be able to reach your site by using http://apps.mysite only on your computer because the host file is resolving the "apps.mysite" to your localhost (127.0.0.1).

    What do I need to change in order to access my subdomain at http://localhost/apps.mysite

    http://localhost/apps.mysite is not a sub-domain is a domain localhost with a folder apps.mysite, a valid subdomain is subDomain.domain.com.

    .com is a top level domain
    domain.com is a domain name
    subDomain.domain.com is a subdomain of domain.com

    Hope it helps.