Skip to main content

ServerName on VirtualHost not working in Apache 2.4.6



I have the following VirtualHosts inside /etc/httpd/sites-enabled/domain.com.conf:




DocumentRoot /var/www/html/
ServerName www.domain1.com




ServerName test.domain2.com
ServerAdmin admin@domain2.com
DocumentRoot /var/www/html/domain2dir
ErrorLog /var/log/httpd/domain2.com-error.log
CustomLog /var/log/httpd/domain2.com-access.log combined



ServerName something.domain1.com
ServerAdmin admin@domain2.com

DocumentRoot /var/www/html/somethingdir
ErrorLog /var/log/httpd/something.domain1.com-error.log
CustomLog /var/log/httpd/something.domain1.com-access.log combined



When I access my server via IP, it shows me /var/www/html/; [OK]



When I access my server via something.domain1.com, it shows me/var/www/html/somethingdir; [OK]




But when I access test.domain2.com, it returns me to http://IP/ instead of taking me to /var/www/html/domain2dir.



Why is that?



PS: domain2dir is a wordpress site.



EDIT: I changed DocumentRoot /var/www/html/domain2dir to something other than domain2dir and it works. I think this means that the problem is the wordpress directory, but I'm not sure why.



Running CentOS 7 with Apache 2.4.6 and PHP 7.2.9.


Answer




For everyone with the same problem, it was inside WordPress's database.
It was pointing to http://IP/domain2dir/etc.etc.etc, so every time Apache redirected to that particular directory, WordPress redirected back to http://IP/.
The solution is to change your http://IP/dir/ inside a few tables to http://domain/.


Comments