Redirecting a Domain Using .htaccess

July 5, 2009
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]

supporting = loving

Since 1999 I've been creating ad-free technical tutorials and essays here. It's a one-person effort that's also my life and livelihood. If it makes your day more livable in any way, please consider supporting the work with a monthly or one-time donation. Your support means a lot to me, and makes all the difference. 🫶🏼