8

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.

Community
  • 1
  • 1
JD Isaacks
  • 56,088
  • 93
  • 276
  • 422

7 Answers7

10

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!

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Yeah that makes since...its just domain1.com is a free hosting account which injects a banner on the top of every page...problem is its making a flex app not work right...so I was trying to host the flex app elsewhere. – JD Isaacks Jun 12 '09 at 15:43
  • As other answers show (user570804's in particular), it is possible (although you need to do it at a level of config above `.htaccess`). It isn't a security hole (although it can help people perform phishing attacks), this is why users need to be vigilant about checking the URL in their address bar when giving information to a website. – Quentin Jul 05 '14 at 08:26
  • @Quentin Security-wise, if you *could* proxy using the `.htaccess` (which you can't, hence this answer remains entirely accurate), compromising a bank's `.htaccess` would allow you to proxy all the bank's users off to an attacker site while the address bar showed the correct URL of hte bank. – ceejayoz Jul 05 '14 at 14:17
3

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>
s3v3n
  • 8,203
  • 5
  • 42
  • 56
DlennartD
  • 51
  • 1
  • 4
1

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.

Ryan Oberoi
  • 13,817
  • 2
  • 24
  • 23
1

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?

Cameron
  • 1,868
  • 3
  • 21
  • 38
0

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

user570804
  • 54
  • 1
  • 5
  • The only proviso here is that you need to put the ProxyPass directive into the main config file, you can't do it at the .htaccess level. – Quentin Jul 05 '14 at 08:29
0

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.

Adrian Lynch
  • 8,237
  • 2
  • 32
  • 40
-1

its impossible using htaccess file.

Tareq
  • 1,999
  • 2
  • 28
  • 57