Hey. I’m trying to implement a permanent redirect from domain.com to www.domain.com.
This is how my .conf file looks like.
/etc/apache2/sites-available/domain.com.conf
<VirtualHost *:80 *:443>
ServerName www.domain.com
ServerAdmin william@domain.com
DocumentRoot /var/www/domain.com/public_html
ErrorLog /var/www/domain.com/logs/error.log
CustomLog /var/www/domain.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domain.com
Redirect permanent / http://www.domain.com
</VirtualHost>
<VirtualHost *:443>
ServerName domain.com
Redirect permanent / https://www.domain.com
</VirtualHost>
This doesn’t work. It works if I want to achieve the opposite (www.domain.com to domain.com) however - obviously after changing a few things.
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!
You can set up an CNAME record through the DigitalOcean DNS panel. To add a CNAME record, first click on the domain that you’d like to edit
Once you’ve done that, click the Add Record button
From there, select the CNAME Record button and enter a name for the record. The CNAME records point to a site’s canonical name. When entering your CNAME record, enter what you need the record to look up in the Name field, and then add the record it resolves to in the Hostname field.
In Name: www In Hostname: @
and this will do the work
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.