Report this

What is the reason for this report?

Apache's mod_rewrite or Digital Ocean's DNS Records?

Posted on May 17, 2013

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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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]

Ah I see; I thought having only one of them works :X

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.