Monday, February 15, 2016

Redirect 301

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

Redirect an old domain to a new domain
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

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

Force non www. version of domain to be used
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.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]