Rewriting domains with .htaccess

Redirect 301 to another Domain using .htaccess

Sometimes you might have a situation where you have a hoster selling you a simple „webspace package“, who provides you a default domain like „webspace123.hoster.net“. And you do not want your site to be accessible through that domain. You can simply rewrite every Request using not your desired Domain with a htaccess rule like this:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !yourdomain.net$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.net/$1 [L,R=301]

This just takes every Domain which does not match with „yourdomain.net“ and changes it to „http://www.yourdomain.net“.