Creating a domain alias in Apache is done by either modifying an existing VirtualHost directive or by creating a new one. Here’s a step-by-step guide on how to do it:
1. VirtualHost is a term used by Apache that allows the server to respond to requests for different IP addresses, hostnames and ports. Each website you host gets its own VirtualHost.
First, you need to access the Apache configuration file. Depending on your Apache installation, the apache2.conf file can generally be found at either:
```
/etc/apache2/apache2.conf
/etc/httpd/httpd.conf
```
Open the file with a text editor (like Vim, Nano, or Gedit).
1. Find existing VirtualHost block for your domain. If you don’t have any yet, you can create a new VirtualHost block. They usually look like this:
```
```
1. Inside the VirtualHost block, to create a domain alias, you’ll use the `ServerAlias` directive. This directive is then followed by the alias domain you want to create.
```
```
In the above example, `www.example.com` is an alias for `example.com`. Both URLs will lead to the same webpage when entered in a web browser.
1. Save the configuration file, and exit the text editor.
1. You should validate your configuration changes to ensure there are no syntax errors by running:
```
sudo apachectl configtest
```
If it returns “Syntax OK”, you’re good to go. If not, you need to fix the reported issues.
1. Restart the Apache web server to apply your changes:
```
sudo service apache2 restart
```
Or use this command if the previous doesn’t work
```
sudo systemctl restart apache2
```
You have now made a domain alias in Apache. The domain alias can now be accessed in any web browser. You may need to wait a few minutes for the changes to propagate throughout the internet.
Notes:
Make sure the alias you are adding has the correct DNS setup, meaning the alias (or ‘www’ version) should be pointing to your server IP where you have Apache installed.