- Unsupervised Learning
- Posts
- Redirecting a Domain Using .htaccess
Redirecting a Domain Using .htaccess
![clean-coding-best-practices](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/6120410c-ffd5-4519-93e6-c8be234842e8/clean-coding-best-practices.jpg)
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]