Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please bear with me while I try to explain some htaccess gymnastics I'd like to perform.

I have this domain: eamorr.somesite.com, at 192.168.100.100.

It is serving pages from my public_html folder as expected.

Now, I want to use the following address:

www.somesite.com/eamorr

I do not have control over www.somesite.com (192.168.99.99), however my sysadmin has allowed me to place a .htaccess file in the eamorr folder. I am not allowed, under any circumstances, to place anything else in the eamorr folder for reasons I do not know.

What I want to happen is this:

User navigates to www.somesite.com/eamorr/some_page.php

User is fed some_page.php from eamorr.somesite.com/some_page.php (i.e. 192.168.100.100/some_page.php).

I'd like this to be as seamless as possible -- i.e. when a user navigates to http://www.somesite.com/eamorr/some_page.php they get served some_page.php and are oblivious to the fact that some_page is coming from a different server (192.168.100.100)

http://www.somesite.com/eamorr should be in the address bar of the user's browser at all times and not http://eamorr.somesite.com -- my boss "just wants it that way"...

Is this possible to do using .htaccess?

share|improve this question
up vote 3 down vote accepted

It sounds like what you want is what is called a "reverse proxy", and it's a job for Apache's mod_proxy. However, you can't set this up in a .htaccess file -- it has to be done in a different context. Perhaps someone here knows better, but I don't think what you're asking for will be possible with a single .htaccess file alone.

share|improve this answer

Use Apache mod_proxy to point to another server. Apache docs here.

This worked well:

ProxyPass /blog http://blog.example.com/
ProxyPassReverse /blog http://blog.example.com/

But only after the proxy modules were loaded correctly:

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_html_module /usr/lib/apache2/modules/mod_proxy_html.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so

Notes

  • Because of CloudFlare I also had to host the blog from a different hostname, not *.example.com.
  • I added Disallow: / to my blog.example.com/robots.txt. Like this search engines will not start indexing in two locations. And search engines will simply ignore blog/robots.txt.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.