Basic 301 redirection not working

February 5, 2015 1.3k views

I have two domains forwarding to my digital ocean account, both are working and showing the correct files.

However one is an old domain that I want to forward to my new one.

I have gone through the steps of making sure mod_rewrite is on and have added this to the .htacces next to the index.html file that both of these domains are serving.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^$ [OR]
  RewriteCond %{HTTP_HOST} ^$
  RewriteRule (.*)$$1 [R=301,L]

However when pulling this update into my site, going to the old domain is not forwarding to the new domain.

My site is in the default location which on my server is /var/www/html/

Do I instead need to do this in a conf file possibly? I have two other websites I'm hosting on my server that I setup to go to specific folders via a .conf file, not sure if that has anything to do with this issue.

2 Answers

Your .htaccess should do the trick. If you have enabled mod_rewrite you will also need to make sure that your virtualhost configuration has AllowOverride All instead of AllowOverride None set for your web root directory. Otherwise apache will ignore directives in the .htaccess file.

  • Yeah I checked the configuration for the default and it said alloweoverride all. I eventually found that moniker (my dns) had the option to forward one domain to another. so I got it working that way, but I don't know why my .htaccess never worked.

    I ran the usual terminal commands I found on google to make sure mod rewrite was enabled.

Have another answer? Share your knowledge.