: Phantom vhost forwarding from example.com to example.net I'm running apache2 on Ubuntu 16.04 LTS, and Let's Encrypt Certbot for SSL certificates. I have two domains. Regardless of http or https,
I'm running apache2 on Ubuntu 16.04 LTS, and Let's Encrypt Certbot for SSL certificates.
I have two domains. Regardless of http or https, www or non-www, I want them to land at example.com and example.net respectively.
I have 4 .conf files per domain: HTTP WWW, HTTP NON-WWW, HTTPS WWW, HTTPS NON-WWW. HTTPS NON-WWW should always be the final result.
Site 01: example.com
example.com -forwards to- example.com [OK] www.example.com -forwards to- example.com [OK] www.example.com -forwards to- example.com [OK] example.com works as expected [OK]
Site 02: example.net
example.net -forwards to- example.net [OK] www.example.net -forwards to- example.com [ERROR] www.example.net -forwards to- example.net [OK] example.net works as expected [OK]
I would like www.example.net to forward to example.net, not example.com
My .conf files:
##Site 01: example.com - HTTP NON-WWW .conf##
<Directory /var/www/html/example.com/public_html>
Require all granted
</Directory>
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html/example.com/public_html
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
RedirectMatch permanent ^/(.*) example.com/ </VirtualHost>
##Site 01: example.com - HTTPS WWW .conf##
<IfModule mod_ssl.c>
<Directory /var/www/html/example.com/public_html>
Require all granted
</Directory>
<VirtualHost *:443>
ServerName example.com DocumentRoot /var/www/html/example.com/public_html
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
RedirectMatch permanent ^/(.*) example.com/
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
##Site 01: example.com - HTTPS NON-WWW .conf##
<IfModule mod_ssl.c>
<Directory /var/www/html/example.com/public_html>
Require all granted
</Directory>
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/html/example.com/public_html
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
##Site 02: example.net - HTTP WWW .conf##
<Directory /var/www/html/example.net/public_html>
Require all granted
</Directory>
<VirtualHost *:80>
ServerName example.net DocumentRoot /var/www/html/example.net/public_html
ErrorLog /var/www/html/example.net/logs/error.log
CustomLog /var/www/html/example.net/logs/access.log combined
RedirectMatch permanent ^/(.*) example.net/ </VirtualHost>
##Site 02: example.net - HTTP NON-WWW .conf##
<Directory /var/www/html/example.net/public_html>
Require all granted
</Directory>
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html/example.net/public_html
ErrorLog /var/www/html/example.net/logs/error.log
CustomLog /var/www/html/example.net/logs/access.log combined
RedirectMatch permanent ^/(.*) example.net/ </VirtualHost>
##Site 02: example.net - HTTPS WWW .conf##
<IfModule mod_ssl.c>
<Directory /var/www/html/example.com/public_html>
Require all granted
</Directory>
<VirtualHost *:443>
ServerName example.com DocumentRoot /var/www/html/example.net/public_html
ErrorLog /var/www/html/example.net/logs/error.log
CustomLog /var/www/html/example.net/logs/access.log combined
RedirectMatch permanent ^/(.*) example.net/
SSLCertificateFile /etc/letsencrypt/live/example.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.net/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
##Site 02: example.net - HTTPS NON-WWW .conf##
<IfModule mod_ssl.c>
<Directory /var/www/html/example.com/public_html>
Require all granted
</Directory>
<VirtualHost *:443>
ServerName example.net
DocumentRoot /var/www/html/example.net/public_html
ErrorLog /var/www/html/example.net/logs/error.log
CustomLog /var/www/html/example.net/logs/access.log combined
SSLCertificateFile /etc/letsencrypt/live/example.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.net/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
More posts by @Marchetta884
1 Comments
Sorted by latest first Latest Oldest Best
You simply have a typo in one of your virtual hosts:
ServerName example.com DocumentRoot /var/www/html/example.net/public_html
...
RedirectMatch permanent ^/(.*) example.net/
The ServerName is wrong. You don't have a virtual host set up for example.net at all because of the typo. That means that example.net falls back to the default (first) virtual host. That is why it gets redirected to the wrong thing.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.