I have an Ubuntu server with the following domains:

sub-staging.example.com sub.example.com

While testing the site via mobile, I noticed the phone would force the url to:

www.sub.example.com

Which would show page not found, DNS error.

So to fix this I added a CNAME record to the main domain (hosted elsewhere on Cpanel) and pointed the CNAME: www.sub.example.com to sub.example.com.

This works... except for one thing.

My staging domain is loading instead of the sub.example.com domain.

How do I fix this?

Ok this was easy to solve, looking at the /etc/apache2/sites-available/example.com.conf file I note that I had forgotten to add the alias to www.sub.example.com

<VirtualHost *:80>
   ServerName sub.example.com
   ServerAlias www.sub.example.com   <---- I had forgotten this
   Redirect permanent / https://sub.example.com/
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin someone@example.com
        ServerName sub.example.com
        ServerAlias www.sub.example.com

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.