I'm setting up a apache with a

RewriteRule ^/?(.*) http://www.myhost.com [P]

It already works, but the page that is displayed only contains text. Images, styles etc are all lost. What am I missing here?

If I manually go to myhost.com it works of course as expected.

  • Where's the rule set? What are the URLs of the resources are failing, and how are they linked in the HTML of the loaded page? What response codes are you getting for those resources? – Shane Madden Aug 4 '12 at 20:27
  • The URL is myhomemachine/manager:8080. If I access my proxy, it is redirecting by RewriteRule. I don't have any "ruleset". Now, I only get the text from the apache server test site. Any styles or images are lost. – membersound Aug 5 '12 at 10:08
  • 1) That URL is not using port 8080, it's using 80. Change to http://myhomemachine:8080/manager. 2) By "Where's the rule set", I mean: what file and where in the file is your RewriteRule located? 3) Can you use your browser's debugging tools to provide more information about what's happening when the resources are failing to load? – Shane Madden Aug 5 '12 at 17:58

You should append the path to the destination URL:

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

(And, by the way, there's a slash missing in the URL.)

  • MIssing slash was just a type, thnx. No I do not want to append anything to my destination url. I just want to call myhost.com, which displays a webpage. Regardless of what is entered to access my ReverseProxy... And the new page now looses all styles. – membersound Aug 3 '12 at 12:51
  • That means that you also rewrite styles such as domain.com/style.css to www.myhost.com. This is exactly why you lose the styles. – Oliver Aug 3 '12 at 12:56
  • Hm how can I prevent this? I just want the new page to be proxied through as it is. But the user should not be aware of this, that's why I'm doing the ProxyPass [P]. – membersound Aug 3 '12 at 13:05
  • You need to also proxy the css files and images that are needed to show the page. This is for example done with the rule that is in my answer. – Oliver Aug 3 '12 at 13:09
  • With your rule I'm just getting a 404 could not be found. Eg: If I go to localhost/test, then te remapping takes place to: myhost.com/test. which results in 404, because "test" does not exist on myhost server. And I do not want to display test, just myhost.com with all its content. – membersound Aug 3 '12 at 13:11

Oliver answer is just fine: but remember also that, even if you're apparently using mod_rewrite, when using the [P] modifier, it's mod_proxy which is doing the actual work. So you should also add the "ProxyPassReverse" directive, like this:

ProxyPassReverse / http://www.myhost.com/ [P]

See Apache docs for references.

  • I'm using a reference to a txt file within my RewriteRule. Did not show this here as it would only cause more confusion. So I cannot use ProxyPassReverse with this txt file. Or could I somehow? – membersound Aug 3 '12 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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