fbpx
Home » Blog » 301 Redirects – How To Redirect Your Website URLs

301 Redirects – How To Redirect Your Website URLs

Using 301 redirects can help improve your Search Engine rankings and consolidate your visitor statistics. It’s relatively easy to implement and will help preserve those search engine rankings for existing pages.

Why use a 301 redirect?

Lets say you are looking to redesign an existing page on your website to take advantage of a new interest shown by a customer community. Renaming the web page with the new relevant keywords will of course help to improve it’s search engine rankings, however, in doing that you will loose all the existing search engine information on the old page you have just redesigned.

Using a 301 redirects will preserve the existing search engine rankings and allow you to add onto it using your new design.

Consolidating your domains

If you use any type of web visitor stats software then you will know that all the information it gathers is relative to your main home URL domain. But are you sure everyone is using the same reference?

For example, some people may type in www.yourdomain.com or jusy simply yourdomain.com.

Your visitor stats software will likely see these URLs as two different websites and will gather independent information respectively. Not what you really want.

A 301 redirect from yourdomain.com to www.yourdomain.com will solve this problem and allow your website to benefit from all the variations of URLs a visitor will type in.

Configuring a 301 Redirect

This will require editing a web server configuration in most cases so if you’re not confident of what you’re doing, please get a professional web designer to help you out.

Below you will find some 301 redirect configurations for popular web servers and services.

Apache (.htaccess) – Redirect Old Domain to New Domain

Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Please REPLACE www.newdomain.com in the above code with your actual domain name.

In addition to the redirect I would suggest that you contact every back-linking site to modify their back-link to point to your new website.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite module enabled.

Apache (.htaccess) – Redirect domain.com to www.domain.com

Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Please REPLACE domain.com and www.newdomain.com with your actual domain name.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite module enabled.

Apache (.htacces) – Redirect an old web page to the new web page

This useful if you are moving pages around as part of a restructuring effort for an SEO campaign but don’t want to loose all the stats for the old page.

Create of modify the .htaccess file. It should have the minimum lines at the top of the file

Options +FollowSymlinks
RewriteEngine on

1. Place this code in your .htaccess file:

redirect 301 /oldfolder/oldpage.htm  http://www.yourdomain.com/newpage.html

2. If the .htaccess file already has lines of code in it,
skip a line, then add the above code.

3. Save and upload the the .htaccess file to the root folder of your Apache server

4. Test it by typing in the old address to the page you’ve changed. You should be immediately taken to the new
location.

Notes: 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.htm (the original folder path and file name)

http://www.you.com/new.htm (new path and file name)

When the search engines spider your site again they will follow the rule you have created in your .htaccess file.
The search engine spider doesn’t actually read the .htaccess file, but recognizes the response from the server as valid.

ISS Redirect

In internet services manager, right click on the file or folder you wish to redirect

Select the radio titled “a redirection to a URL”.

Enter the redirection page

Check “The exact URL entered above” and the “A permanent redirection for this resource”

Click on ‘Apply’

PHP Redirect

<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>

ASP Redirect

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.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.new-url.com");
}
</script>

JSP Redirect

<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>

CGI Perl Redirect

$q = new CGI;
print $q->redirect("http://www.new-url.com/");

Ruby on Rails Redirect

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end

Keep In Touch

Wil

Wil is a dad, consultant, developer, conference organiser, speaker and business mentor. He co-organizes the WordPress Sydney meetup group and has been on the orgnising committee for WordCamp Sydney since 2014. He speaks at many technical events and contributes to the WordPress open source project. His likes are chillies, craft beer and electrogravitics.
If You Enjoyed This Post
Join Our Newsletter
Give it a try, you can unsubscribe anytime.
Close