By LeeChilli
We have a main website (main.com) and some subdomain (1.main.com) website for the same domain on one server all using HTTPS.
If you try and access the main domain using a subdomain not in use (2.main.com) it’ll take you to the last subdomain setup on the website (1.main.com) rather than the main website (main.com)
Is there a way to point the non setup subdomains to correctly redirect to the main website.
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!
It sounds like you have a wildcard DNS entry in place that directs any requests for *.main.com to the same IP address. In this case, Apache will route the request to the VirtualHost that matches. If no VirtualHost is an exact match, it will use the first one defined. So you’ll want to ensure that main.com is defined first:
<VirtualHost *:80>
ServerName main.com
DocumentRoot "/www/main.com"
</VirtualHost>
<VirtualHost *:80>
ServerName 1.main.com
DocumentRoot "/www/1.main.com"
</VirtualHost>
If you have the VirtualHosts in separate files, the order they are loaded will determine it. So use a filename like: 000-main.com.com to ensure it is loaded first.
For more info, see the Apache documentation and check out this tutorial:
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.