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 /xmodx.com/web/content/ folder (via FTP), will perform the redirect when a visitor goes to http://xmodx.com in their Web Browser.

Redirect a single page:

Redirect 301 /pagename.php http://xmodx.com/pagename.html

Redirect an entire site:

Redirect 301 / http://xmodx.com/

Redirect an entire site to a sub folder

Redirect 301 / http://xmodx.com/subfolder/

Redirect a sub folder to another site

Redirect 301 /subfolder http://xmodx.com/

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

RedirectMatch 301 (.*)\.html$ http://xmodx.com$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 (.*) http://www.newdomain.com/$1 [R=301,L]
#Redirect to www location
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://xmodx.com/$1 [r=301,nc]
#Redirect to www location with subdirectory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^(.*)$ http://xmodx.com/directory/index.html [R=301,NC]

Below is a tool that will check your redirect to ensure that it is indeed search engine friendly: http://www.webconfs.com/redirect-check.php

Leave a Reply

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