Sunday, 8 September 2013

Redirect Your Website With Using a .htaccess File

301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. I am explain here how to create a .htaccess file to redirect your site such as non www to with www code / index.php code / index.html !

301 redirect non www to with www code

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.xyz\.com
RewriteRule (.*) http://www.xyz.com/$1 [R=301,L]

301 redirect index.html and index.php to non index.html and index.php

index.php code

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php?$ http://www.xyz.com/$1 [R=301,L]

index.html code

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.xyz.com/$1 [R=301,L]

No comments:

Post a Comment