0

Is it possible in the apache config file to use regular expressions in the ServerName and ServerAlias field to have 2 domains use the exact same config file vs. creating 2 for each domain. I was trying something like this, but was getting an error from Apache:

<VirtualHost *:80> ServerAdmin [email protected] ServerName [test.com|test.net] ServerAlias [www.test.com|www.test.net] DocumentRoot /var/www/test.com/public_html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 
5
  • Refer stackoverflow.com/questions/11169843/… Commented Jun 28, 2020 at 14:09
  • Yes I saw the wild card at the beginning for subdomains, but am wondering what the syntax would be and if it is possible to have one config file for two domains like test.com and test.net and more possibly. Commented Jun 28, 2020 at 15:10
  • I will suggest you to use wildcard for sudomain. You can refer stackoverflow.com/questions/758351/… Commented Jun 28, 2020 at 15:24
  • They are not subdomains one is a .com and another is a .net Commented Jun 28, 2020 at 16:13
  • I do not think Apache does that. One trick could be to put that <VirtualHost> as the first in the configuration, remove ServerName and ServerAlias and use it as the default. When Apache cannot match the name, it uses the first <VirtualHost> if finds from the top. But that means that any connection to reach your port 80 would match that one as well. For that type of config, I never combine two sites together (in company servers), since I want my logs to be separated for each site. And sites come and go, so it is easier when they are not coupled. YMMV Commented Jun 29, 2020 at 5:19

1 Answer 1

0

I have a similar situation and I ended up with something like this (in your terms):

<VirtualHost test.net:80> ServerAdmin [email protected] ServerName test.net ServerAlias test.com www.test.net www.test.com DocumentRoot /var/www/test.com/public_html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.