By roscoejack
I’m trying to run a new website from a sub-domain on my droplet, as well as a website at the root of the domain, e.g. example.com and new.example.com serving from different directories.
I’ve set up the directories, created virtual host files for each site, and enabled both sites.
Currently, every time I visit new.example.com I get 301 redirected to example.com. If I disable the example.com site using a2dissite, then new.example.com loads as expected.
The only reason I can think of this happening (I’ve investigated .htaccess files and ruled that out) is if the following line were catching the sub-domain because it doesn’t contain ‘www’:
‘ServerName example.com’
Is this possible, or is the problem likely somewhere else and if so what could it be? I’ve exhausted my Google searches : /
I would like my main site to continue to serve without ‘www’ if possible, whilst also running the new sub-domain on the same droplet.
Thanks for any help.
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!
Hi,
I think I can provide you a few information to solve that issue with Apache Named VirtualHosts.
When you configure Apache with VirtualHosts, it keeps serving the first virtualhost that was enabled as the “default Virtualhost”. Unless you declare a ServerAlias directive, Apache will not catch any subdomain more than the one declared in ServerName. At the end, if Apache doesn’'t know the ServerName asked for, it returns the first virtualhost that was activated.
In your case, I think you should check that both your VirtualHosts contains a ServerName directive, and you should ensure that your VirtualHost declaration starts with <VirtualHost *:80>, to be sure you can handle multiple domain names on the same port.
You should also check the /etc/apache2/ports.conf file, to be sure it contains a NameVirtualHost *:80 line. If you have all this set, then you can restart Apache2, and your webserver will serve 2 websties accordingly to their domain names.
Hope this could help.
Regards,
– rustx
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.