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

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.



Solution 1:[1]

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>

Solution 2:[2]

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.

Solution 3:[3]

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?

Solution 4:[4]

Why is this not possible? Seems like a reasonable task as long as your Apache has mod_proxy installed:

ProxyPass /photos http://domain2.com/photos/

http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypass

Solution 5:[5]

A way around it, if the page at domain.com/photos is a server side script, do an HTTP call and serve up the response.

In ColdFusion:

<cfhttp url="another.domain.com/photos">

<cfoutput>#CFHTTP.FileContent#</cfoutput>

They'll be an extra request, but it'll get you the output you want.

Solution 6:[6]

its impossible using htaccess file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 s3v3n
Solution 2 Ryan Oberoi
Solution 3 Cameron
Solution 4 user570804
Solution 5
Solution 6 Tareq