301 redirect with .htaccess except one file

Last Modified at 2019-06-25 21:29:29

Hello 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.

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.

About Lipku

Categories

In order to optimize our website and to be able to continuously improve it, we use cookies. By continuing to use this website, you agree to the use of cookies. For more information about cookies, please visit our Privacy policy.