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).
<meta http-equiv=”refresh” content=”0;url=http://myDomain.com/myNewUrl.php”/>
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
.htaccess file
At the web server level, add the following line to your .htaccess file of your Apache installation.
redirect 301 /myOldPost/postName.php http://myDomain.com/myNewPost/postName.php
The following code changes are made at the page level:
C#.NET
<script runat=”server”>
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(”HTTP/1.1 301 Moved Permanently”);
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.
Share:
These icons link to social bookmarking sites where readers can share and discover new web pages.