Logo
My Journal
Blog

Timeline

Blog

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://log.xmodx.com in their Web Browser.

Redirect a single page:

[php]Redirect 301 /pagename.php http://log.xmodx.com/pagename.html[/php]

Redirect an entire site:

[php]Redirect 301 / http://log.xmodx.com/[/php]

Redirect an entire site to a sub folder

[php]Redirect 301 / http://log.xmodx.com/subfolder/[/php]

Redirect a sub folder to another site

[php]Redirect 301 /subfolder http://log.xmodx.com/[/php]

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

[php]RedirectMatch 301 (.*)\.html$ http://log.xmodx.com$1.php[/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:

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

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 Comment