I'm trying to have 3 different domains and subdomains on my VPS:
- pd.example.com
- intranet.example.com
- example.com
I have configured them, but for some reason each subdomain is getting redirected to the same index.html that is in the root directory of example.com
The screenshot for intranet.example.com
:
The screenshot for example.com
:
Here is the virtualhost for intranet.example.com
:
<VirtualHost *:80>
ServerAdmin soporte@example.com
ServerName intranet.example.com
ServerAlias www.intranet.example.com
DocumentRoot "/var/www/intranet/"
<Directory "/var/www/intranet/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.intranet.example.com [OR]
RewriteCond %{SERVER_NAME} =intranet.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Here is the virtualhost for example.com
:
<VirtualHost *:80>
ServerAdmin soporte@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example
<Directory /var/www/example>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Did I configure my virtualhosts correctly?
These are the 443
Virtual hosts for example.com:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin soporte@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example
<Directory /var/www/example>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
</VirtualHost>
</IfModule>
This is for intranet.example.com:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin soporte@example.com
ServerName intranet.example.com
ServerAlias www.intranet.example.com
DocumentRoot "/var/www/intranet/"
<Directory "/var/www/intranet/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.intranet.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.intranet.lsgob.us/privkey.pem
</VirtualHost>
</IfModule>
.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST} [R=301,L]
example.com
) is also redirected to the subdomainwww.intranet.example.com
(at least, that is what's showing in your screenshots) - or are your screenshots back to front? But your screenshots also showHTTPS
- so we need to see your<VirtualHost *:443>
containers. You also don't need to use mod_rewrite to redirect to HTTPS in a vhost context, you should use the simpler mod_aliasRedirect
. But don't you also want to canonicalise the www/non-www subdomain? – MrWhite Aug 29 '18 at 12:32index.html
that is in the root directory" - Also, please clarify whether this is an external redirection (3xx response), as you suggest or simply that the sameindex.html
document is being served? – MrWhite Aug 29 '18 at 13:57<VirtualHost *:443>
containers in your question. And if you are also using.htaccess
then please include these also. Since you have access to the server config and you are performing redirects in the server config then there does not seem to be any reason to do the same in.htaccess
? Your screenshots are strange as they appear to show redirects going in opposite directions? – MrWhite Aug 30 '18 at 13:37