301 redirect with .htaccess except one file

No comments
301 redirection with .htaccess except one fileHello Friends, I am back again. Some day ago, I wanted to move my blog to new domain and automatically send to the visitors and googlebot to new website, but some pages had to remain on current website.  That means I needed to redirect all the requests to new website, except some files. By following below trick, I was able to make the things happen.

First create a .htaccess file and put the below code. Below code will ensure that all the folders and files will get correctly redirected to your new domain except 1 file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?9do\.in$ [NC]
RewriteCond %{THE_REQUEST} !/donotredirect\.html [NC]
RewriteRule ^ http://www.9do.info%{REQUEST_URI} [L,R=301,NE]

Please change olddomain.com to your old domain name and newdomain.com to your new domain. Also change donotredirect.html to your file name that you don’t want to redirect to your new domain. If you want to redirect all the files and folders then remove this line from above code.

RewriteCond %{THE_REQUEST} !/donotredirect\.html [NC]

Now upload the .htaccess file to your olddomain.com. You are done!
Please note that, This .htaccess method of redirection only works on linux server.

Please share this tutorial with your friends and write your opinion in the comment box below.

No comments :

Post a Comment