DevHeads.net

Strrange behavior of VirtualHosts in Apache (CentOS6)

Hello,

there is a short explanation about virtual hosts in Apache ...
<a href="https://wiki.centos.org/TipsAndTricks/ApacheVhostDefault" title="https://wiki.centos.org/TipsAndTricks/ApacheVhostDefault">https://wiki.centos.org/TipsAndTricks/ApacheVhostDefault</a>

the `hostname` gives a different donmain name than what should be hosted ...
e.g. `hostname` is host.example.org and the domain to be hosted is
example.com, so I did this:

<VirtualHost 1.2.3.4:80>
ServerName host.example.org
DocumentRoot /var/www/default
</VirtualHost>

# used to get let's encrypt for the mail server
<VirtualHost 1.2.3.4:80>
ServerName mail.example.org
ServerAlias smtp.example.org
DocumentRoot /var/www/mail
</VirtualHost>

<VirtualHost 1.2.3.4:80>
ServerName <a href="http://www.example.com" title="www.example.com">www.example.com</a>
DocumentRoot /var/www/domain
</VirtualHost>

<VirtualHost 1.2.3.4:80>
ServerAlias *.example.com
DocumentRoot /var/www/catchall
</VirtualHost>

the DocumentRoot directories are empty,
only in /var/www/default I have a PHP script: host.php
<?php
header( "Content-type: text/plain" );
printf( "Host: '%s'\n", $_SERVER['HTTP_HOST'] );
?>

now the strange behavior;

<a href="http://mail.example.org/" title="http://mail.example.org/">http://mail.example.org/</a> <-- works
<a href="http://smtp.example.org/" title="http://smtp.example.org/">http://smtp.example.org/</a> <-- doen't work
<a href="http://smtp.example.org/host.php" title="http://smtp.example.org/host.php">http://smtp.example.org/host.php</a> <-- gives the HTTP_HOST (PHP-script),
but why?

<a href="http://www.example.com/" title="http://www.example.com/">http://www.example.com/</a> <-- works
<a href="http://hello.example.com/" title="http://hello.example.com/">http://hello.example.com/</a> <-- doesn't work
<a href="http://hello.example.com/host.php" title="http://hello.example.com/host.php">http://hello.example.com/host.php</a> <-- gives the HTTP_HOST (PHP-script),
but why?

doesn't work does mean, that access/errors are logged in logfile of wrong
virtual host ...

where is my mistake;

Thanks,
Walter