19

Is it possible to for a domain e.g. www.myclient.com to have a sub directory hosted on a completly different (our) server?

They don't want to point subdomain.myclient.com to our servers so they want it as folder www.myclient/subdomain/

Thanks in advance.

Lizard
  • 43,732
  • 39
  • 106
  • 167
  • No, unless you are prepared to start using the myclient.com server as a proxy. It requires access to Apache configuration, will cost a lot of bandwidth but *should* be possible that way. – Pekka May 16 '11 at 15:09
  • Not even with a .htaccess rule `RewriteRule magazine/(.*) http://myotherdomain.com/$1` ?? – Lizard May 16 '11 at 15:34
  • @Lizard that will work, but it will *redirect* the user to the new location instead of just rewriting the URL. The new location will show up in the browser's address bar. – Pekka May 16 '11 at 15:34
  • Is there not a way of keeping the original URL then? – Lizard May 16 '11 at 15:36
  • @Lizard only if using Apache as a proxy. But it's not necessarily that difficult: http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypass – Pekka May 16 '11 at 15:41
  • @Lizard you're welcome. Note that this will of course double your traffic, because every requested file will have to be fetched from Server 2, and served by Server 1 (I assume you know that, but to make sure for future generations) – Pekka May 16 '11 at 16:19

3 Answers3

20

As discussed in the comments, your only option is a Proxy. Everything else (Like mod_rewrite / Alias) will do a header redirect, and expose the target address to the user.

However, Apache's proxying doesn't seem to be that complicated. The most basic example is

ProxyPass /mirror/foo/ http://backend.example.com/

Note that a proxy will of course double your traffic, because every byte requested will have to be fetched from the remote machine.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 1
    This works like a charm and its also very practical to put in a Location tag on your virtualhosts – a1an Oct 03 '12 at 09:52
  • Why not DNS server of my main server cannot redirect to another server and serve as a proxy? – Radenko Zec May 03 '15 at 16:40
  • 1
    @Radenko but how would you tell a DNS server to point to a different server when the request is for a specific subdirectory? The DNS server doesn't even see the full requested URL. – Pekka May 03 '15 at 16:53
6

There are two different mechanisms that you might be able to use to accomplish this. What you use will depend on the setup you have as well as what permissions you have on the server from the hosting company if this is not a dedicated server.

The first option is to map to the second server using the file system, then use mod_alias to point the subdirectory to the mapped location. This requires that the two servers be networked together, for instance if you have one server dedicated to a specific server, but own and can safely network the servers at the file system level.

Another option would be to set up Apache to act as a proxy. This does require some advanced programming to configure but the system can be set up so that requests to the specified subfolder would be passed on to the remote web server. This can be used when the remote server can't be networked at the file system level, but lets you simulate the workings of a remote subdomain.

Wige
  • 3,788
  • 8
  • 37
  • 58
  • 1
    +1 for mentioning the possibility of Aliasing if a file share connection is present, good idea – Pekka May 16 '11 at 16:17
0

Could you use Amazon CloudFront because it can map different paths to differnt servers ?

Paul Taylor
  • 13,411
  • 42
  • 184
  • 351