Forum Moderators: phranque

Message Too Old, No Replies

Displaying content from another site

         

knkk

10:00 am on Jun 18, 2010 (gmt 0)

10+ Year Member



I have 2 sites, example.co.in and example.com, hosted on 2 different servers.

When someone accesses example.co.in/a/b.php?c=d, I want it to show the HTML of example.com/a/b.php?c=d

This site has to be search-engine-friendly, so I do not want to use an iframe, or even AJAX, since all the content has to be in the HTML - basically, example.co.in/a/b.php?c=d should output just the same HTML as example.com/a/b.php?c=d would.

I could use echo file_get_contents(example.com/a/b.php?c=d) in example.co.in, but that would mean a request goes from the example.co.in server to the example.com server, and then the output would come to the example.co.in server, which would then send it to the user. That could mean time delay, and also that I am using twice the bandwidth - since there is data transfer from both my servers.

Apache rewrite will change the URL, which I do not want to happen - I want people who browse example.co.in to stay on it.

I was wondering if any of the numerous experienced people on this forum would be able to suggest a solution :). Thank you very much for your time!

g1smd

1:11 pm on Jun 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The GET or using a Proxy are the only two ways, and that will always result in two requests and a time delay.

However, by having the same content at two different URLs you are creating a Duplicate Content Problem.

knkk

1:28 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



No - this content will not be available from example.com, it will be available only on example.co.in. As in, while example.co.in/a/b?c=d and example.com/a/b?c=d will theoretically deliver the same content, there will be no URL example.com/a/b?c=d on example.com. So there will be no duplicate content problem.

I'm a newcomer to Apache, and some words can get lost on me to the extent I do not even know what phrases to Google. When you said GET above, did you mean the same as I did when I mentioned the
echo file_get_contents bit?

Also, can you give some idea of how the Proxy you mentioned above works, or maybe point me to some resource I can read up at?

Thank you very much for your time!

g1smd

1:52 pm on Jun 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, the GET was your example.

There's several hundred prior examples of what you want to do in this forum. I suggest you scan the results for likely threads and then read as much as possible to find all the pitfalls: [google.com...]

knkk

2:48 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



Thank you, g1smd. I tried putting this in my .htaccess for example.co.in:


<Location />
ProxyPass http://www.example.com
</Location>


but it gave a 500 Internal Server Error.

This is a shared server, so I do not have access to httpd.conf. Would you think maybe something is disabled there that is causing the error? Or do I need to add anything to my code?

jdMorgan

2:48 pm on Jun 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A reverse-proxy implemented with Apache mod_proxy does essentially the same thing at the server level that your proposed scripted solution would do: It sends a request to the other server to get the content, and then sends the content returned by that server back to the client.

See the Apache mod_proxy documentation at apache.org for more info. Note the discussion of the X-Forwarded-For header and its use for custom logging on the example.com server. This allows the original client's IP address to be passed from example.co.in to example.com so that it can be logged. Otherwise, the example.com server will log all reverse-proxied requests as originating at example.co.in.

Another solution -if feasible- would be to host both domains on the same server, and share all or part of the filespace between the two "sites." This would allow example.co.in to have direct access to the shared files and scripts stored in example.com's filespace, without requiring the extra HTTP transactions and bandwidth.

Jim

knkk

2:52 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



Thank you, jdMorgan. I think I hit the submit button for my previous button a few seconds before you did. I'd read the mod_proxy page (well, some of it) and came up with some lines, which were giving a 500 error.

I'll try some more stuff from there.

knkk

2:53 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



Also, I'd like Googlebot to see that example.co.in is hosted in India (I believe that helps significantly, since example.co.in targets India), so I want to do this roundabout stuff. example.com is hosted in the US.

jdMorgan

2:58 pm on Jun 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The syntax of ProxyPass is wrong. It needs both a requested URL-path-part to match, and a target URL to pass the matching requests to...

Study the documentation and all linked resources carefully, and don't get in a hurry -- If you do, it will cost you much more time, now (getting it working) or later (fixing possibly-very-bad unintended results).

Jim

knkk

3:54 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



Thanks, jdMorgan. I guess the syntax would have to be:


ProxyPass / http://www.example.com/


I just discovered that mod_proxy is something that has to be installed :). Perhaps that is reason that I am getting that error. I have written to my hosting company, and they've said they'll do it in a few hours.