Security Verified
Browse Categories
 Affiliates
 Backup & Restore
 Billing & MyAccount FAQs
 Control Panels
 Customer Tools
 Databases
 Dedicated Servers
 DNS and Domain Registration
 Email
 Glossary
 Network
 News
 PCI Compliance
 Pre-sales FAQ
 Publishing Your Site
 Reseller Tips
 Search Engine Optimization
 Security Topics
 SSL and HTTPS
 Support: Getting Help
 Virtual Desktops
 Virtual Servers
 Website Design & Development
 Website Errors

DotNetNuke Hosting
SQL 2008 R2 / IIS 7.5 Hosting
WordPress Hosting
Forex Trader Hosting
Personal Desktop Hosting

301 redirect

Article ID: 411

 Back to Search

Question: How can I implement a 301 Redirect ("permanent redirect") on my site?  For example, I want to redirect all users who come to www.domain.com to go to domain.com...

Answer: There are several ways to implement a 301 redirect, as described below:

Please note that 3Essentials is NOT responsible for the results achieved with any of these code samples, to either site performance or search engine ranking or placement.  You are STRONGLY advised to fully research and understand any functions you implement in your site as well as the impact to your site function and search engine ranking and placement.  Use this code at your own risk.  

Here's also an excellent reference on this topic: http://www.webconfs.com/how-to-redirect-a-webpage.php

HTML Redirection

You can do a redirect with the html meta tag, but we would advise you not to due to it's misuse, most search engines will de-index a page with this usage.  Use one of the solutions noted below.

301 Redirect Using htaccess (for linux hosting customers only)

Using htaccess to accomplish the 301 redirect is highly suggested due to it being fairly convenient to manage, rather than setting redirects on each individual page, you can simply add the redirect code to the .htaccess file.

Here is how to do it:

  1. Create a file on the root directory of your website, name it ".htaccess".
  2. Open the .htaccess file using notepad or what ever text editor that you prefer.
  3. Add this into the .htaccess file, save it and then upload it to your web server:

Redirect 301 /old/old.html http://www.you.com/new.html

NOTE: Don't add "http://www" to the first part of the statement - place the path from the top level of your site to the page. Also ensure that you leave a single space between these elements:

redirect 301 (the instruction that the page has moved)
/old/old.html (the original folder path and file name)
http://www.domain.com/new.html (new path and file name)

301 Redirect Using Mod_Rewrite (for linux hosting customers only)

Mod_Rewrite has got to be one of the most useful modules a server can have in terms of SEO, it allows you to organize the file structure of your web site in a dynamic yet simple fashion. In this example I show a useful method of 301 redirecting with mod_rewrite.

When somebody links to your website, sometimes they dont always link to you in the way that you want them to. If somebody links to www.yoursite.com and somebody else links to yoursite.com, Google will assign a separate pagerank for each of those. By inserting the below example into your .htaccess file, it will solve the problem by redirecting anything linking to domain.com to www.domain.com, also redirecting the pagerank.

RewriteEngine On
rewritecond %{http_host} ^yoursite.com
rewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L]

301 Redirect with IIS7's Rewrite Module (for Windows/IIS7 based hosting only)

See the Enforce a Primary Hostname configuration that 3Essentials can implement for you, described in this article: http://knowledge.3essentials.com/web-hosting/article/1256/URL-Rewrite-mod_rewrite-for-Windows-on-IIS-7.x.html

 301 Redirect Using PHP

Simply add this code to your page or script:

  • <?
  • header( "HTTP/1.1 301 Moved Permanently" );
  • header( "Status: 301 Moved Permanently" );
  • header( "Location: http://www.new-url.com/" );
  • exit(0); // This is Optional but suggested, to avoid any accidental output
  • ?>

  

301 Redirect Using ASP

Simply add this code to your page or script, within the script tags:

  • <%@ Language=VBScript %>
  • <%
  • Response.Status="301 Moved Permanently"
  • Response.AddHeader "Location", http://www.new-url.com/
  • %>

  

301 Redirect Using ASP .NET

Simply add this code to your page or script: 

  • <script runat="server">
  • private void Page_Load(object sender, System.EventArgs e)
  • {
  • Response.Status = "301 Moved Permanently";
  • Response.AddHeader("Location","http://www.new-url.com/");
  • }
  • </script>

 

 
Downloads Associated With This Article
No downloads are currently associated with this article.

© 2001 - 2012 3Essentials Inc.
Terms Of Service | Privacy Policy | Copyright Policy | Affiliates