What Is a 301 Redirect? A Quick Guide to Effective URL Forwarding
A 301 redirect is the most effective, search engine-friendly method for webpage redirection, ideal for guiding visitors from one URL to another. This process not only enhances user experience but also serves a critical SEO role by ensuring that search engines access only one version of each page, thus avoiding duplicate content penalties. By consolidating multiple URLs into a single dominant URL, you minimize the risk of these penalties.
For technical reasons, it is advisable to implement a 301 redirect only when no Content Management System (CMS) is available, particularly if your website operates on a Unix®/Apache® server. Modifying files in the presence of a CMS carries the risk of breaking your entire website. Since our Customer Service and Technical Support teams do not assist with the creation of such custom codes, this guide aims to equip you with the necessary knowledge for successful URL redirection and 301 redirect setups.
In this article, we will discuss:
- When to Use a 301 Redirect
- Methods of URL Redirection
- Redirect Old Domain to New Domain (.htaccess redirect)
- Redirect to WWW (.htaccess redirect)
- How to Redirect to HTML Pages
When to Use a 301 Redirect
Implementing a 301 redirect is essential in various scenarios to maintain SEO value and ensure a seamless user experience. Here are some common use cases:
Changing URLs. When you reorganize your website or change poorly optimized URLs, a 301 redirect ensures that visitors and search engines are directed to the new URLs without losing link equity.
Recreating content. When you rebuild content on a new page, use a 301 redirect to maintain the SEO value of the original page. This is particularly useful if you want to use a different web page template or structure.
Consolidating content. If multiple pieces of content overlap or compete for the same keywords, consolidate them into one resource and use 301 redirects for the old URLs. This helps avoid duplicate content issues and consolidates ranking signals.
Migrating domains. During a domain migration, implement page-to-page 301 redirects to transfer SEO value from the old domain to the new one. This ensures that your site's visibility and search rankings are preserved.
Routing multiple domains to one page. If you own multiple domains that should point to the same website, use 301 redirects to guide all traffic to a single primary domain. This avoids duplicate content penalties and enhances user experience.
Fixing broken links. If you have moved or deleted a page and users are encountering 404 errors, a 301 redirect can guide them to the appropriate page, improving user experience and maintaining search engine rankings.
Methods of URL Redirection
Explore the following methods for effective URL redirection:
ColdFusion Redirect
<.cfheader statuscode="301" statustext="Moved permanently"> <.cfheader name="Location" value="http://www.newdomain.com">
PHP Redirect
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.newdomain.com" );
?>
ASP Redirect
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.newdomain.com/"
%>
ASP.net Redirect
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.newdomain.com");
}
</script>
JSP (Java) Redirect
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.newdomain.com/" );
response.setHeader( "Connection", "close" );
%>
CGI PERL Redirect
$q = new CGI;
print $q->redirect("http://www.newdomain.com");
Redirect Old Domain to New Domain (.htaccess redirect)
Create a .htaccess file using the code below to ensure all directories and pages of your old domain are correctly redirected to your new domain. Place the .htaccess file in the root directory of your old website (the same directory where your index file is located)
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
This setup ensures seamless redirection, preserving your SEO efforts and enhancing user experience by guiding visitors to the appropriate pages on your new domain. Additionally, we recommend contacting each backlinking site to update their links to point to your new website.
Redirect to WWW (.htaccess redirect)
Create a .htaccess file with the code below to ensure that all incoming requests to domain.com are automatically redirected to www.domain.com. Place this .htaccess file in the root directory of your old website, which is typically where your index file resides.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]
How to Redirect to HTML Pages
For HTML page redirection on Unix servers, please refer to the section "Redirect to WWW" detailed above. This guide provides step-by-step instructions tailored for Unix hosting environments.