Performing a 301 redirect


A 301 redirect is an HTTP status message that permanently diverts a user or search engine to URL that is different from the one originally requested. It is an effective way to ensure that users and search engines will find your cloud site. This article will show you how to perform a 301 redirect on your cloud site.

The following examples are specific to PHP and work only if your cloud site is configured for PHP. The examples will not work for IIS (ASP / ASP.NET).

To convert your site from Windows (IIS) to Linux (PHP) technology, see How do I change my site's default technology?

To rewrite from ASP.NET, see How do I rewrite URLs from ASP.NET?

Basic redirect examples

The following examples are basic 301 redirect examples that use the .htaccess text file. Save this file in the folder from which you want to perform the redirect.

For example, if you place the .htaccess file in the /www.domain.com/web/content/ folder (via FTP), the redirect occurs when a visitor goes to http://www.domain.com in their browser.

Redirect a single page:

Redirect 301 /pagename.php http://www.domain.com/pagename.html

Redirect an entire site:

Redirect 301 / http://www.domain.com/

Redirect an entire site to a subfolder:

Redirect 301 / http://www.domain.com/subfolder/

Redirect a subfolder to another site:

Redirect 301 /subfolder http://www.domain.com/

Redirect using RedirectMatch 301:

The following syntax redirects any file with the .html extension to use the same filename using the .php extension instead.

RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php

Rewrite examples

You can also perform a 301 redirect by rewriting with .htaccess.

Redirect from old domain to new domain:RewriteEngine on RewriteBase / RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Redirect to www location:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]

Redirect to www location with subdirectory

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/directory/index.html [R=301,NC]

Redirect from www to non-www location

RewriteEngine on
RewriteBase / RewriteCond %{HTTP_HOST} ^www.domain.com [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Tip: Use the following SEO tool to verify that your redirect is search engine friendly: http://www.webconfs.com/redirect-check.php

 



Was this content helpful?




© 2014 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER