Redirecting a Domain Using .htaccess

Redirecting a Domain Using .htaccess

Here’s how to redirect from one domain to another within Apache using .htacess. This is how to do it permanently (using an HTTP 301 redirect) rather than using a 302, which search engines don’t like.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^danielmiessler.com$ [NC]
RewriteRule ^(.)$ https://danielmiessler.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^dmiessler.com$ [NC]
RewriteRule ^(.)$ https://danielmiessler.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^danielmiessler.com$ [NC]
RewriteRule ^(.*)$ https://danielmiessler.com/$1 [R=301,L]

Source link