301 Redirect ALL "Except" - Keep Google Webmaster Tools Verified after 301

3 replies
Hi Warriors!
I wanted to share this Tutorial I made, as I feel it will be very useful to many people here.

I'm going to show you how to Exclude a specific File/Folder/Subdomain from a Full 301 Redirect.

301 Redirects are used when Permanently moving a Website from one Domain to another, or similarly, when pointing a URL location to another defined URL destination.

I've seen many website owners asking for solutions to this problem (301 URL Exclusion) on various sites, but most answers didn't give the desired results or a working solution.

My method is Condensed/Simplified, Effective and Very Easy to use and implement.


Here is a real-life scenario of when this method can become very useful:

Originally Posted by Andrew Davis

Many/Most Webmasters use Google Webmaster Tools (GWT), which helps them to track their Website's current status in Google's Search Engine rankings.

To properly use GWT, you must verify each of your websites that you want to track.

You are given a file to upload to your server like this: "google123456789abcdefg.html"


After your site has been verified in GWT tools, you may want to redirect that site to a new Domain later on, for whatever reason.

GWT helps you verify to Google that your address has been changed.

When you successfully 301 your Old site to the New one however, your GWT Verification File becomes inaccessible.
Thus, you will eventually lose Ownership Verification on that Domain in GWT. (I'm not sure how important that is, but it doesn't look good.)
I'm going to show you how to do a Full Parallel 301 Redirect (as I call it), while keeping your Old Domain Verified in Google Webmaster Tools.

By "Parallel" I mean that the Files and Folders from the Old Domain point to the same location on the New Domain. (Matched Pattern)

(From) http://old-site.com/folder1/file.php
=>
(To) http://new-site.com/folder1/file.php

==================================================

First: Locate and Open/Edit the relevant .htaccess file.

This should be located in your server, in the appropriate folder for your Old Domain.

If you cannot find it, try creating a New File with the name .htaccess

(If you get an error saying that the file already exists, try exploring your Server/FTP's Interface Options to reveal hidden "dot" (.) files)


Now paste this code in your .htaccess file.
(If other code exists there, you can try placing my Code after everything else)

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} old-site.com [NC]
RewriteCond %{REQUEST_URI} !^/google123456789abcdefg.html$
RewriteRule ^(.*)$ http://new-site.com/$1 [R=301,L]

Replace "old-site.com" with the Domain you are Redirecting Away From.

Replace "new-site.com" with the Domain you are Redirecting Towards.

Replace "google123456789abcdefg.html" with the File that you want to Exclude from the Full 301.

In this case "google123456789abcdefg.html" is an .html file on the Root Folder of the Old Domain.


And there you have it!
A Full 301 Redirect from your Old Site to your New Site WHILE keeping your GWT Verification File intact.

==================================================

Now I'll show you some Other Very Useful 301 Exclusion methods.

To use these methods, Replace them with or Place them Below this line of Code from the first example:
RewriteCond %{REQUEST_URI} !^/google123456789abcdefg.html$

You can use any number of these Codes simultaneously.
They will Exclude a desired File/Location from the Full 301 Redirect.


Exclude a File in a Folder:
RewriteCond %{REQUEST_URI} !^/folder1/file.php$


Exclude an Image on the Domain Root:
RewriteCond %{REQUEST_URI} !^/image.jpg$


Exclude Selected Filetypes:
RewriteCond %{REQUEST_URI} !.(jpg|png|css|js|php)$


Exclude a Folder:
RewriteCond %{REQUEST_URI} !^/folder1/$


Exclude a File in a Sub-Folder:
RewriteCond %{REQUEST_URI} !^/folder1/folder2/file.php$


Exclude a Subdomain:
RewriteCond %{HTTP_HOST} !subdomain.
(Will affect all files within that Subdomain)

==================================================

If you don't want the "Parallel Redirect" (Matched Pattern), and you want ALL files to point specifically to 1 location (Root in this example), change the last line of our Code to this:

RewriteRule ^(.*)$ http://new-site.com/ [R=301,L]

(Just remove the "$1")


Other Notes:
1) This Method works for both the www. and non-www. forms of your old URL, so no need to include 2 lines for both forms.

2) If you want the New Site Location to include "www." in the URL, then simply add that to the last line like this:

RewriteRule ^(.*)$ http://www.new-site.com/$1 [R=301,L]

3) I excluded Backslashes from my Code for simplicity; to make things easier for people.
I believe that "Escaping" the "dots" is unnecessary for these types of redirection.

You may add Backslashes Before your "dots" if you chose. (\.)

----------

Thanks for reading!
I hope that this Tutorial has been of help to you.

Please let me know if you've tried this out and whether it is working or not for your situation.
Feel free to suggest changes or improvements to my Codes.

-Andrew Davis
#301 #google #htaccess #redirect #tools #verified #webmaster

Trending Topics