Basic 301 redirection not working

  • Posted February 5, 2015

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.


Submit an 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.

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.

This comment has been deleted

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.