Basic 301 redirection not working

Posted February 5, 2015 4k 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.

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

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.

Hi, experts, I am trying 301 redirections for my site *( *so I used the following code, but it is not working! Can anyone please find out the error and help me to solve the 301 issue.

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

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.pages\ HTTP/
RewriteRule ^index.pages$ [R=301,L]

Please help to redirect my site.