Apache2 website hosting for Linux

when hosting on a Linux variant, you may need a config file that will do proper redirect

create the a file, naming it a meaningful name ending in *.conf.
ie: if your domain is domain.com, create the name:  domain.com.conf
———————————–

<VirtualHost *:80>
ServerAdmin [Email Address here]
ServerName [subdomain].[domain].com
ServerAlias [subdomain].[domain].com
DocumentRoot /var/www/[codeDirectory]/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/[codeDirectory]/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
———————————–
on the “server Name” line, if it is top level domain, exclude the “subdomain” section.  otherwise insert it in.

if you have any other domains you’d like to redirect here, server alias will be inserted on following line.  for instance:

you want people to go to www.domain.com, the “ServerName” will be www.domain.com, and alias will be domain.com  you can switch them if desired.

when the file is ready, upload to /etc/apache2/sites-available/ location and do the following

1) a2ensite domain.com.conf

2) systemctl restart apache2

changing the domain.com.conf to what you named your file and do a apache2 restart apache.