How can I redirect to using DigitalOcean DNS?

December 18, 2012 15.9k views
I've tried to use cname, A record, and I didn't get it to work.
1 comment
7 Answers
Create CNAME record:
Tried htacess ?
We've done this redirect multiple times and it's always been through a redirect on the web service layer whether that's in Apache or Nginx.

In Nginx you can do this very simply:
server {
listen 80;
return 301$request_uri;

If you are using Apache let us know.
  • What need to be done in Apache?

    On the .htaccess I have used :

    <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
    Options -MultiViews

    RewriteEngine On
    # Redirect Trailing Slashes...
    #RewriteRule ^(.*)/$ /$1 [L,R=301]
    # Redirect all non-www requests to your site to the www version
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]


    But non-www wouldn't redirect to www

nightflash is correct. 'www' pointing to '' is the right way to do it in Digital Ocean's DNS settings. Don't forget the '.' at the end of your domain.
About how long does it take for this to propagate? I still only see the default apache page at whereas has been fine. Do I need to restart the server?
@david: Apache config changes take effect instantly after restarting Apache (assuming your DNS records are proper). You need to add a VirtualHost as follows:
<VirtualHost *:80>

Redirect permanent /

Ubuntu 12.04:

Ubuntu 14.04:
by Etel Sverdlov
This tutorial shows you how to set up a new directory, how to grant the correct permissions, how to add content to a new page, how to turn on virtual hosting, and how to, if needed, set up local hosts. Virtual Hosts are used to run more than one domain off of a single IP address and allows you to run multiple sites off of a single DigitalOcean droplet. This tutorial describes how to set up virtual hosts with Apache.

Sorry to re-open this thread..

I need to redirect: to other URL

I'm using Ngix, how can I do this? May I do this in DNS or in nginx config?


  • You can do that by adding an nginx server block as follows:

    server {
      listen 80;
      return 301;

    Make sure you replace the bits in red to suit your needs.

Have another answer? Share your knowledge.