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

Posted May 17, 2013 7.1k views
I was trying to figure out how to redirect a website such that will lead to instead of giving me a 404 error when I saw this Apache guide: 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!

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.

Submit an Answer
3 answers
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.

@ A
www CNAME @

www A

Add the following to your .htaccess.

# From www to non-www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

From non-www to www
# Force www in HTTP
RewriteEngine On
# line below is optional
# RewriteCond %{REQUEST_URI} !^/(blog|
RewriteCond %{HTTP_HOST} ^
# RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R=301,L]
Ah I see; I thought having only one of them works :X