Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 638
Timo002 Avatar asked Apr 15 '13 07:04

Timo002


People also ask

Can we redirect one domain to another domain?

URL redirect (URL forwarding) allows you to forward your domain visitors to any URL of your choice (to a new domain or a different website). You can set 301 (Permanent), 302 (Unmasked), and Masked (URL Frame) redirects for the domain names pointed to BasicDNS, PremiumDNS or FreeDNS.

Can you redirect a domain without owning it?

Hi, Depending on your domain registar you can do URL forwarding (URL forwarding is in fact a fancy name for a 301 redirect). In this case you don't need a hosting account. For example if you host with Godaddy you can easily do that using the control pannel of your domains.


1 Answers

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

like image 98
anubhava Avatar answered Oct 02 '22 09:10

anubhava