I am trying to set up some automation on my local dev machine. Normally I start all my projects like this
Open Hosts file, set up a DNS entry like 127.0.0.1 example.com www.example.com
Open httpd-vhosts.conf
file and add an entry, something like this below
<VirtualHost *>
DocumentRoot "/path/to/xampp/htdocs/example.com"
ServerName example.com
ServerAlias www.example.com
</VirtualHost>
What I am trying to achieve is to set up the environment in such a way that, I shouldn't have add this entry in my httpd-vhosts.conf
every time I want to work on a new host.
Rather I would like to have one global entry in httpd-vhosts.conf
that can handle all the domains and map them to their respective directories
so if I have a list of records in my hosts
file like this
127.0.0.1 example.com
127.0.0.1 mysite.com
127.0.0.1 google.com
127.0.0.1 abc.com
and a folder structure like this
/htdocs/
/example.com/
/mysite.com/
/google.com/
/abc.com/
It should automatically map to those directories without the need of adding the VirtualHost
record in the httpd-vhosts.conf
file.
I can guess that this can be achieved by adding a wildcard entry in httpd-vhosts.conf
(I don't know how) and then adding some redirect rules in .htaccess
file placed in /htdocs/
to map them to their directories.
So eventually,
- How to set up a wildcard entry in
httpd-vhosts.conf
- How to set up exact rewrite rules in
.htaccess
file in/htdocs/
This is something that I thought of, there might also be a better way to do this.