Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

N00b question. I have an URL

and would like to call an internal resource


I tried:

AllowCONNECT 5732
ProxyPass /game/ http://localhost:5732/ nocanon
ProxyPassReverse /game/ http://localhost:5732/

but the HTML coming back contained links that didn't get /game/ prepended and JS and CSS broke. So I tried:

 RewriteEngine On
 RewriteRule ^/game(.*) http://localhost:5732$1

but that sends a redirect (which of course doesn't work) to the browser.

What do I get wrong? My goal is:

 http://myserver/game --> http://localhost:5732/ 

Help is greatly appreciated

share|improve this question
up vote 3 down vote accepted

If your Apache version is recent enough (2.4+), you can try mod_proxy_html

ProxyPass /game http://localhost:5732 nocanon
ProxyPassReverse /game http://localhost:5732
<Location /game/>
    ProxyHTMLEnable On
    ProxyHTMLURLMap / /game/

For older versions of apache, you can try with mod_substitute. However, this requires you to manually write your regexes. This could be a starting point:

ProxyPass /game http://localhost:5732 nocanon
ProxyPassReverse /game http://localhost:5732
<Location /game/>
    SetOutputFilter SUBSTITUTE
    Substitute s|href='/|href='/game/|nq
    Substitute s|src='/|src='/game/|nq

Of course, the exact configuration will depend on what output you currently get from your game server.

share|improve this answer
For the moment I'm stuck with 2.2, so I'll give mod_substitude a try. I guess I'll also need Substitude s|href='http : // localhost/|href='http : //|nq – stwissel Aug 26 '12 at 12:17
2 Questions: Will the ' catch both ' and " and what does the |nq do? – stwissel Aug 26 '12 at 12:18
The |nq are modifiers to change the behavior of the Substitute command, you can check out the different modifiers in the documentation. In short, the 'q' modifier increases performance (but it may break more complex configurations, for this kind of simple substitutions you should be fine though). The 'n' modifier disables regex behavior, which allows you to simplify the used syntax a bunch and also improves performance. – brain99 Aug 26 '12 at 12:27
And no, the ' only matches exactly that character. So if you have some occurrences with ' and some with ", you will need two Substitute rules. Note that if you have spaces in your rules, you need to enclose them in quotes as well. You can also escape quotes within your rules. For example, suppose you need to modify a javascript: window.location.href = "/";, then your Substitute rule could look like Substitute "s|window.location.href = \"/\";|window.location.href = '/game/';|nq". – brain99 Aug 26 '12 at 12:32

The first version you did, with ProxyPass and ProxyPassReverse, is the most common way to do what you want. The problem is that whatever it is you've got running on localhost:5732 is the thing that creates the HTML that will be sent back - and it doesn't know that it's not called localhost:5732. Your proxypass doesn't change the pages that are passed through, it so if your game contains all the wrong links, that's what you'll see.

So, to make this work, you need to reconfigure your game thingy so it knows to present its links etc as your.server/game instead of localhost.5732.

share|improve this answer
Hi Jenny, what you describe is exactly what happened. I got the HTML back but it contained all relative links (e.g. stylesheets) based on / instead of /game/ – stwissel Aug 26 '12 at 12:12

Your Answer


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.