By cakePlease
hi there, Am having an issue that i’ve been banging my head on the past weekend… I’ve setup 2 vhosts on a newly configured ubuntu 14 server, one is mean to be a primary domain www.mydomain.com, and the other is meant to be a subdomain, sub.mydomain.com. There is a wildcard SSL certificate that both vhosts shares.
Problem: When i navigate to (i’ve masked my host file to point the domains to my server IP for this testing) sub.mydomain.com, the browser is always redirected to www.mydomain.com.
Expected behavior: When i navigate to sub.mydomain.com, it should not redirect to the primary domain, but rather load the site that is hosted at the sub domain.
The vhost configurations for both domains are as follows: www.mydomain.com:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
#Redirect everything to https:
RewriteEngine on
RewriteRule ^(.*)$ https://www.mydomain.com$1 [R=301,L]
</VirtualHost>
<VirtualHost mydomain.com:443>
ServerName mydomain.com
ServerAlias www.mydomain.com
ServerAdmin admin@mydomain.com
DocumentRoot /var/www/mydomain.com/html
<Directory /var/www/mydomain.com/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.mydomain.com
RewriteRule ^(.*)$ https://www.mydomain.com$1 [R=301,L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/mydomain.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/mydomain.com.key
SSLCACertificateFile /etc/apache2/ssl/intermediate.crt
</VirtualHost>
<VirtualHost *:80>
ServerName sub.mydomain.com
#Redirect everything to https:
RewriteEngine on
RewriteRule ^(.*)$ https://sub.mydomain.com$1 [R=301,L]
</VirtualHost>
<VirtualHost sub.mydomain.com:443>
ServerName sub.mydomain.com
ServerAdmin admin@mydomain.com
DocumentRoot /var/www/sub.mydomain.com/html
<Directory /var/www/sub.mydomain.com/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/mydomain.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/mydomain.com.key
SSLCACertificateFile /etc/apache2/ssl/intermediate.crt
</VirtualHost>
Can anyone let me know what im doing wrong and offer some assistance? The SSL cert works as we are currently using it on another server on Mediatemple, with the same domains. We’re looking to migrate those 2 sites to DO so we want the same SSL and security setup.
thanks
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
hm…unfortunately, when i do a curl, it just hits my current live website. So i cant tell what the issue is. Im assuming you mean to run that command from the server itself?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.