skip to Main Content

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:xampphtdocsmysiteapps. 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

2

Answers


  1. Start by creating a VirtualHost for localhost in case you want to use that for a bit of fiddling

    # Virtual Hosts
    #
    <VirtualHost *:80>
      ServerName localhost
      ServerAlias localhost
      DocumentRoot "C:/xampp/htdocs"
      <Directory "C:/xampp/htdocs"/>
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
      </Directory>
    </VirtualHost>
    
    ## then add main site
    <VirtualHost *:80>
      ServerName mysite.local
      ServerAlias www.mysite.local
      DocumentRoot "C:/xampp/htdocs/mysite/"
      <Directory "C:/xampp/htdocs/mysite/"/>
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
      </Directory>
    </VirtualHost>
    
    ## then add the sub domain
    <VirtualHost *:80>
      ServerName aps.mysite.local
      ServerAlias www.aps.mysite.local
      DocumentRoot "C:/xampp/htdocs/mysiteapps/"
      <Directory "C:/xampp/htdocs/mysiteapps/"/>
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
      </Directory>
    </VirtualHost>
    

    You will need to add these 2 sites to your C:windowssystem32driversetchosts file like this

    127.0.0.1 mysite.local aps.mysite.local
    ::1 mysite.local aps.mysite.local
    

    For the change to the HOSTS file you will either need to reboot or refresh the DNS Cache like this from a command window

    >ipconfig /flushdns
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search