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 / folder (via FTP), the redirect occurs when a visitor goes to in their browser.

Redirect a single page:

Redirect 301 /pagename.php

Redirect an entire site:

Redirect 301 /

Redirect an entire site to a subfolder:

Redirect 301 /

Redirect a subfolder to another site:

Redirect 301 /subfolder

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$$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 (.*)$1 [R=301,L]

Redirect to www location:

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

Redirect to www location with subdirectory

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} [NC]
RewriteRule ^(.*)$ [R=301,NC]

Redirect from www to non-www location

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

Tip: Use the following SEO tool to verify that your redirect is search engine friendly:


© 2015 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