How can I do a 301 redirect?

Here are some basic 301 redirect examples via the .htaccess text file (please create or upload this file in the folder you want to perform the redirect from).

For example placing the .htaccess file into the / folder (via FTP), will perform the redirect when a visitor goes to in their Web Browser.

Redirect a single page:

Redirect 301 /pagename.php

Redirect an entire site:

Redirect 301 /

Redirect an entire site to a sub folder

Redirect 301 /

Redirect a sub folder to another site

Redirect 301 /subfolder

You can also redirect based on file extensions via the following syntax:

RedirectMatch 301 (.*)\.html$$1.php

This will redirect any file with the .html extension to use the same filename but use the .php extension instead.
You can also perform 301 redirects using rewriting via .htaccess.

Here are three examples:

#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]

Below is a tool that will check your redirect to ensure that it is indeed search engine friendly:

Leave a Reply

Your email address will not be published. Required fields are marked *