Redirecting a Domain Using .htaccess

July 5, 2009
Daniel Miessler
clean-coding-best-practices

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]

Reader-supported

For roughly 29.8077 years I've written here, ad-free—3,084 essays and tutorials and counting. If it's useful to you, a monthly or one-time donation keeps it going. 🫶🏼