Aj Khandal

Permanent 301 Redirect using .htaccess

301 redirect tells search engine and other users that old link is replaced by new link. There are many different kind of 301 redirection.

Redirect individual files on the same domain

To make this kind redirection you need to open .htaccess file and put this code.

Redirect 301 /oldfile.htm /newfile.htm

Redirect individual files on the other domain

Redirect 301 /oldfile.htm http://demo.net/newfile.htm

Redirect an old domain to a new domain

RewriteEngine on
RewriteCond %{HTTP_HOST} ^demo.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.demo.com [NC]
RewriteRule ^(.*)$ http://demo.net/$1 [L,R=301,NC]

301 Redirect

Force www. version of domain to be used

RewriteEngine on
RewriteCond %{HTTP_HOST} ^demo.com [NC]
RewriteRule ^(.*)$ http://www.demo.com/$1 [L,R=301,NC]
Force non www. version of domain to be used

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

Redirect all files with certain extension

RewriteEngine On
RewriteCond %{REQUEST_URI} .php$
RewriteRule ^(.*).php$ /$1.htm [R=301,L]

Do You Have An Interesting Project? ​

$10/ HR

Need Help?