Redirect to other domain but keep typed domain

After looking on the internet for about an hour, I didn't find the answer to my question. So I'm searching with the wrong keywords or what I want is not possible.

What I want:
I have multiple domains with different extensions, for example:

  • mydomain.be
  • mydomain.nl

Now what I want is that the mydomain.be is redirected to mydomain.nl. The solution for this I have found on the internet and shown below, with the need of .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.be$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.be$
RewriteRule (.*)$ http://www.mydomain.nl/$1 [R=301,L]

With this code, when you type mydomain.be you will be redirect to mydomain.nl. But also the URL in the addressbar is changed to mydomain.nl. What I want is to keep the URL in the addressbar mydomain.be.

So, mydomain.be:

  • keep URL
  • show content of mydomain.nl

How To?


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 -MultiViews
RewriteEngine On
RewriteBase /

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>