Forum Moderators: phranque

Message Too Old, No Replies

point one directory to different server

maintain url/different server

         

soapystar

4:16 pm on Nov 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if i want to switch servers for certain dirctories but maintain the url in the broswer can this be done with htaccess?

i.e.
mydomain.com/directory/ should point to server newservername/directory but the file will still show mydomain.com/directory/file.htm in the browser?

Sop i have the ability to switch where the directory loads from without constantly changing the url.

jdMorgan

4:31 pm on Nov 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can proxy the request through to the other server.

Downsides:

  • All traffic for this special URL passes through *both* servers.
  • Server handling 'special' URL always sees the other (main) server as the referrer, so tracking/logging on the 'special' URL must be done on the main server.

    You can set up the proxy in httpd,conf, or use a mod_rewrite RewriteRule with the [P] flag.

    Jim

  • soapystar

    5:04 pm on Nov 27, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Thanks jd
    Your way sounds great except i dont follow exactly how it works. Currently i am redirecting directory requests to the other server and was working on rewriting the url on the other server but keep ending up with a redirect rather than just the url being rewritten.

    In the example where main server is using domain.com..and www.domain.com/directory is being redirected to server_name/directory..how would i use htaccess to have server_name/directory/file.html show as www.domain/directory/file.html

    Im really one grain short of newbie with regards to htaccess so sorry if im not understanding what should be obvious.

    jdMorgan

    7:43 pm on Nov 27, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    This kind of project is much easier to comprehend if you forget the 'show this as that' mind-set, and think in terms of 'serve content for this URL from that file on that server.' URLs and files are different things, and you can map any URL to any file using rewrites, proxy throughputs, or redirects.

    In this case you want to serve the URL www.domain/directory/file.html from the file at www.anotherdomain/directory/file.html, or so I presume.

    In that case, leaving out all of the setup directives, you'd use


    RewriteRule ^directory/file\.html$ http://www.anotherdomain.com [P]

    in .htaccess in the Web root folder of www.domain.com

    In this case, www.domain.com acts as a proxy to reach the specific content on www.anotherdomain.com.

    Jim

    soapystar

    9:22 pm on Nov 27, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    JD im sorry to admit i cant get this working. First off i wanted to make it wildcard for filenames in other words all domain.com/directory/anyfilename loads the same file from the anotherdomain/directory..the directories are mirrors currently so any filename request from domain.com/directory/example needs to load the anotherdomain/directory/example but with domain.com in the address bar. I understand why i was thinking wrong before and i need to use the p tag to force the use of that server from the domain.com webroot but still cant get the thing to work.

    ! :(

    jdMorgan

    9:25 pm on Nov 27, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member




    RewriteRule ^directory/(.*)$ http://www.anotherdomain.com/directory/$1 [P]

    We're also assuming that mod_proxy is loaded on the server, and that you're allowed to use it.

    Jim

    soapystar

    9:38 pm on Nov 27, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    as usual thanks for your help JD!