Redirect to other domain but keep typed domain Redirect to other domain but keep typed domain apache apache

Redirect to other domain but keep typed domain


It is possible to get it done via mod_rewrite but make sure mod_proxy is enabled in your Apache's httpd.conf. Once that is done enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViewsRewriteEngine OnRewriteBase /RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.be$ [NC]RewriteRule ^ http://www.mydomain.nl%{REQUEST_URI} [L,NE,P]

Take note of flag P which is used for handling the proxy request.

Read more about flag: P in mod_rewrite


Another option without hassling with .htaccess would be to point both domains to the same document root or setting one domain as an alias for the other, depending on how you are able to configure your Apache. However, this has downsides:

  • If your content management system uses absolute URLs a user who clicks on mydomain.nl on a link will be directed to the mydomain.be domain (WordPress does this, as an example).
  • Search engines punish this behaviour by placing you further down on the search results. at least Google does, they have an interesting blog post about duplicate content. Not sure about competitors.

An example apache config could be:

<VirtualHost *:80>    ServerName mydomain.nl    ServerAlias mydomain.be    DocumentRoot /var/www/mydomain.nl/htdocs</VirtualHost>