Theodoros Emmanouilidis

Notes & Thoughts

Search Engine Friendly Redirection

August3

.htaccess method

If you have moved your site to a new domain, a simple thing to do is create an .htaccess file inside the empty root directory of your old domain and paste the following code.

1
2
3
4
5
6
<!--?
header( "HTTP/1.1 301 Moved Permanently" );
header( "Status: 301 Moved Permanently" );
header( "Location: http://www.yournewdomain.com" );
exit(0); // This is suggested to avoid any accidental output
?-->

This method can be used if you want to redirect individual pages and not the entire site. To do this use the following syntax:

1
redirect 301 /data/old_page.html http://www.yourdomain.com/data_new/new_page.html

use the relative path and name of the old page followed by a single space followed by the URL of the new page the old is redirected to.

.htaccess method can also work on servers having the apache mod-rewrite moduled enabled. If you use a hosting enviroment that forbids you access to apache configuration just use the PHP or the above .htaccess method.

Create a blank .htaccess file inside the root directory of your old domain.

Copy and paste the followng code inside the file.

1
2
3
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.yournewdomain.com/$1 [R=301,L]

If mod-rewrite module is enabled all will work fine. If there is already an .htaccess file check if the directives “Options +FollowSymLinks” and “RewriteEngine on” are already present and add the third line to the end of the file. If not, just paste all three lines to the end of the file.

Using .htaccess file and apache mod-rewrite you can redirect all http://www.yourdomain.com traffic to http://yourdomain.com traffic or vice verso , thus preventing search engines to mark the www and non www version of your site as duplicate sites.

Copy the following code to an empty .htaccess file inside the root directory of your domain:

Redirirect to www
1
2
3
4
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,NC]

Again, if an .htaccess file already exists, check if the directives “Options +FollowSymLinks” and “RewriteEngine on” are already present and add the following two lines.

Pages: 1 2

posted under Web Servers

Email will not be published

Website example

Your Comment: