How to redirect a website using .htaccess?

How to redirect a website using .htaccess?

Redirect website http://mydomain.com to http://www.mynewdomain.com

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

Redirect website mydomain.com with and without www requests to http://www.mynewdomain.com

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

Redirect requests from http://mydomain.com to http://mydomain.com/subdirectory i.e. redirecting requests from main domain to a sub-directory.

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

Redirect all http (80) requests of a domain to https (443) i.e. redirecting requests from non-secure port to a secure port.

RewriteEngine On
RewriteCond %{SERVER_PORT}      !443
RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]

This entry was posted on Sunday, December 27th, 2009 and is filed under Linux Administration. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.