SEO Chris Gray on 18 Jun 2007 10:09 pm
The correct way to move a web page to a new URL – the 301 Redirect
A few weeks ago I found myself in a situation where I needed move a blog post to a new URL. In the past I would have never given this task a second thought…rename the slug, update internal links (if any), and done. Enter Search Engine Optimization. Now that I am cognizant of such SEO buzzwords as “Index”, “Page Rank” and “Duplicate Content”, moving a page is no longer a trivial task.
The Problem
By simply moving your page to another URL, you can loose your current ranking for that page in the search index. Any link equity that you have built up over time is lost…not to mention that you will also be serving up 404s to any user that has linked to, or bookmarked your page.
Available Solutions
There are a number of ways to handle moving a page to a new URL but not all are suitable in terms of search engine optimization.
Maintain two copies of the same file
Obviously this solution has duplicate content written all over it and is not recommended. Search engines are cracking down on sites that host duplicate content and you will penalized for doing so.
Meta-Refresh
The meta-refresh tag forces the browser to refresh after a specified period of time. If you specify the URL to your new page in the “content” attribute, the browser will fetch the new URL instead of the current one (effectively redirecting to your new URL).
Some search engines consider the meta-refresh approach a “sneaky redirect” and will penalize you for using it (same goes for using JavaScript to redirect to a new URL).
302 Redirect
Also known as a “Temporary Redirect”, the 302 HTTP header is used to notify the browser that the requested page has temporarily moved to a new URL. This method should only be used when you are truly only temporarily moving your page. Search engines that encounter a 302 redirect will continue to crawl your page from it’s original location.
In the past, 302 redirects have been associated with page hijacking and you may be penalized you for using this method to move your page (just like the meta-refresh method above).
301 Redirect
Also known as a “Permanent Redirect”, the 301 HTTP header is used to notify the browser that the requested page has permanently moved to a new URL. The 301 redirect is the recommended method to move a page to a new URL.
How to implement a 301 Redirect
At the web server level, add the following line to your .htaccess file of your Apache installation.
The following code changes are made at the page level:
C#.NET
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(”Location”,” http://myDomain.com/myNewPost/postName.aspx”);
}
</script>
PHP
header(”Location: http://myDomain.com/myNewPost/postName.php”);
exit();
Java/JSP
response.setStatus(301);
response.setHeader(”Location”, “http://myDomain.com/myNewPost/postName.jsp “);
response.setHeader(”Connection”, “close”);
%>
Conclusion
I have to admit that I initially used a meta-refresh to perform the redirect that I mentioned at the beginning of this post. After (literally) stumbling upon an article on “how to redirect a web page, the smart way” the other night I realized that I was approaching this problem in the wrong manner. I ended up going the .htaccess route because I did not know how to execute PHP from within a post (I’m sure there is a way). Hopefully you will also find this information useful. Please let me know if there is a certain example that you would like me to add (i.e. IIS or Perl perhaps)…I only covered the technologies that I currently use.







on 19 Jun 2007 at 2:12 am 1.stan said …
Use mod_rewrite in .htaccess:
RewriteEngine On
RewriteRule ^myOldPost/(.+)$ http://myDomain.com/myNewPost/$1 [R=permanent,L,QSA]
This is also applicable on IIS if using IIS Mod-Rewrite ( http://www.micronovae.com/ModRewrite/ModRewrite.html ) which supports .htaccess.
on 19 Jun 2007 at 8:40 pm 2.Chris Gray said …
@stan - thanks for the tip. I am still getting used to Apache (sad to say but I have been developing most of my web apps on Windows). Is there any reason to use mod_rewrite over the redirect method in .htaccess…just curious?
on 20 Jun 2007 at 2:10 am 3.stan said …
Hi Chris,
From usability view, you may need to combine redirections with other url rewriting needs, so many developers or webmasters prefer mod_rewrite.
From a technical view, mod_rewrite is more powerful than Redirect or RedirectMatch. If you put conditions (RewriteCond) in the play, then you go beyond simple redirect mapping. For example, the following configuration redirects all broken links to index.php:
RewriteEngine On
RewriteCond %{HTTP_REFERER} .
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.html$ /index.php?404url=$1 [R,QSA,L]
on 27 Jun 2007 at 12:36 am 4.Blogger Backup,Cygwin Alternatives, Oneclick Wordpress Plugin… » Chandrasekhar Vallabhaneni said …
[…] The correct way to move a web page to a new URL ? … - By simply moving your page to another URL, you can loose your current ranking for that page in the search index. There are a number of ways to handle moving a page to a new URL but not all are suitable in terms of SEO. This article explores few of them. […]
on 30 Jun 2007 at 2:01 pm 5.All in a days work… said …
[…] The correct way to move a web page to a new URL – the 301 Redirect Also known as a “Permanent Redirect”, the 301 HTTP header is used to notify the browser that the requested page has permanently moved to a new URL. The 301 redirect is the recommended method to move a page to a new URL. (tags: Redirect) […]
on 07 Jul 2007 at 3:41 pm 6.8 Oddities About Derek Semmler » Derek Semmler dot com said …
[…] Chris Gray :: Chris hasn’t been posting quite as frequently but did recently share some great information on the correct way to use a 301 redirect […]
on 12 Jul 2007 at 10:14 am 7.Safely Move Your Blog (eMoms Group Research Project) | MamaBlogga said …
[…] Chris Gray at SEO Ladder with the codes for meta refresh (which, as he states, is not recommended), PHP, Apache, C#.NET and Java/JSP. […]
on 17 Jul 2007 at 12:17 pm 8.Vern1271 said …
We are redesigning our site using PHP instead of .ASP, what should I do to ensure that all those old .asp links get redirected to their new .php equivalent?
on 21 Jul 2007 at 5:16 am 9.Chris Gray said …
@ stan :: Thanks for the info on mod_rewrite, I will be surely reading up on this topic shortly as I have a project that will require some extensive redirects in the near future.
@ Vern1271 :: Great question, let me see if I can dig up the correct regular expression to do this. I am assuming that you are planning a one to one conversion (i.e. somePage.asp will become somePage.php)? If this is the case it should pretty simple.
on 23 Jul 2007 at 9:45 am 10.Vern1271 said …
Yes Chris…I am using the exact names as the old .asp pages. I read that I could do this using .htaccess…just tell it to redirect “somename.asp” to “somename.php”. Is this correct?
on 23 Jul 2007 at 10:40 pm 11.Chris Gray said …
@ Vern1271 :: I am no expert on apache or mod_rewrite but I think I was able to get the results you were looking for using the following combination. Give it a go; it should redirect all of your .asp pages to their .php replacement:
RewriteBase /
RewriteRule ^(.*)\.asp$ $1.php [R=301,L]
on 26 Jul 2007 at 11:54 am 12.Playing it safe with Search Engine Safe URLs – How to optimize your WordPress Permalink structure - SEO Ladder said …
[…] before you change over to a new Permalink structure. I suggest taking a look my previous post on the proper way to move a web page for additional information on how redirect old links to your new Search Engine Safe […]
on 12 Aug 2008 at 9:00 am 13.Chris said …
301 of the correct method to follow,however strength will inevitably be lost
on 22 Aug 2008 at 5:36 pm 14.Mayor of Kentonville said …
Thank this article is just what I wanted
on 27 Aug 2008 at 9:34 am 15.Chris Gray said …
Thanks, glad to be of some help