Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect to a different domain without changing the URL in the address bar?

Tags:

.htaccess

I want to redirect from:

domain1.com/photos

To:

domain2.com/photos

I want the URL in the address bar to still read:

domain1.com/photos

Is there a way to do this using only .htaccess?


Note:

My .htaccess file for domain1.com is currently completely blank.

like image 399
JD Isaacks Avatar asked Jun 12 '09 15:06

JD Isaacks


4 Answers

No, there isn't a way to do this with .htaccess. Doing so would present a glaring security hole - imagine someone doing this with a bank's website!

like image 196
ceejayoz Avatar answered Nov 04 '22 10:11

ceejayoz


If both are hosted on the same server, do this in your .htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^domain1.com$
  RewriteRule (.*)$ http://www.domain2.com$1 [P]
</IfModule>
like image 26
DlennartD Avatar answered Nov 04 '22 10:11

DlennartD


If you own both domain1 and domain2, you could accomplish this through domain name forwarding. Check your domain name registrar (like godaddy.com) for the options.

No, you can not do it through htaccess file.

like image 44
Ryan Oberoi Avatar answered Nov 04 '22 09:11

Ryan Oberoi


You could open an iframe in domain1.com/photos that shows the contents of domain2.com/photos. But then the url would never change from domain1.com/photos, even when you went to a different page in domain2.

What are you trying to do? It sounds very sketchy. Do you own both domains? Why would you want to duplicate the contents of one site at another address?

like image 30
Cameron Avatar answered Nov 04 '22 09:11

Cameron