I was trying to figure out how to redirect a website such that www.example.com will lead to example.com instead of giving me a 404 error when I saw this Apache guide:
http://httpd.apache.org/docs/2.4/rewrite/remapping.html
I am wondering will this be better than using the DNS records in Digital Ocean’s GUI, considering that the DNS records are still not working despite setting them up last night (They should have propagated by now…)
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!
You have to have DNS records for your subdomains to resolve to your droplet. You should also configure apache properly to redirect from non-www to www (or from www to non-www).
Make sure you point the IP of the server to your dns records. <br> <br>@ A xxx.xxx.xxx.xx <br>www CNAME @ <br> <br>or <br>www A xxx.xxx.xxx.xx <br> <br>Add the following to your .htaccess. <br> <br># From www to non-www <br><IfModule mod_rewrite.c> <br>RewriteEngine On <br>RewriteBase / <br>RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC] <br>RewriteRule ^(.)$ http://domain.com/$1 [R=301,L] <br></IfModule> <br> <br>From non-www to www <br># Force www in HTTP <br>RewriteEngine On <br># line below is optional <br># RewriteCond %{REQUEST_URI} !^/(blog|blog.domain.com) <br>RewriteCond %{HTTP_HOST} ^domain.com <br># RewriteCond %{SERVER_PORT} 80 <br>RewriteRule ^(.)$ http://www.domain.com/$1 [R=301,L]
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.