Note that there are some explanatory texts on larger screens.

plurals
  1. POApache's mod_proxy_html with PHP header("Location:..."); doesn't redirect
    primarykey
    data
    text
    <p>I've googled the crap out of this problem and came up with nothing, so hopefully you guys can help.</p> <p><b>Goal</b><br /> Configure a reverse proxy (using Apache's mod_proxy) to enable access to an internal PHP application over the internet <i>using mod_proxy_html to rewrite URLs in my application.</i></p> <p><b>Problem Description</b><br /> Consider landing.php with only this code:</p> <pre><code>&lt;a href="redirect.php"&gt;redirect.php&lt;/a&gt; </code></pre> <p>and redirect.php with only:</p> <pre><code>&lt;?php header("Location:http://internal.example.com/landing.php"); ?&gt; </code></pre> <p>with this snippet from my httpd.conf</p> <pre><code>UseCanonicalName On LoadFile /usr/lib64/libxml2.so LoadModule proxy_html_module modules/mod_proxy_html.so LoadModule xml2enc_module modules/mod_xml2enc.so &lt;VirtualHost *:80&gt; ServerName example.com &lt;Proxy *&gt; Order deny,allow Allow from all AllowOverride None &lt;/Proxy&gt; ProxyPass / http://internal.example.com/ ProxyPassReverse / http://internal.example.com/ ProxyHTMLLinks a href #Commenting out this line fixes the problem, but I need it for rewriting ProxyHTMLEnable On RequestHeader unset Accept-Encoding &lt;/VirtualHost&gt; </code></pre> <p>When I go to <a href="http://example.com/landing.php" rel="nofollow">http://example.com/landing.php</a> and click "redirect.php" it should take me back to the landing.php page. Instead, I get a "This connection was reset" in Firefox, or "No data received" in Chrome. (FYI, going to <a href="http://internal.example.com/redirect.php" rel="nofollow">http://internal.example.com/redirect.php</a> redirects correctly.)</p> <p><b>The Question:</b><br /> Why the redirect would fail going through the reverse proxy, and how can I fix this?</p> <p><b>Hints</b><br /> I've discovered a few things that could be helpful...</p> <p>I know that if I comment out "ProxyHTMLLinks a href", this will work correctly. But obviously, this is the rewrite functionality I need.</p> <p>I can also change the redirect.php page to the following, this works correctly:</p> <pre><code>&lt;?php header("Location:http://internal.example.com/landing.php"); ?&gt; random text </code></pre> <p>I guess this text somehow does something to the page or HTTP headers that make mod_proxy_html (or more specifically ProxyHTMLLinks) operate differently than without it.</p> <p>I can also change the redirect.php page to the following and have it work:</p> <pre><code>&lt;?php header("Location:http://internal.example.com/landing.php"); header("Content-Type:"); ?&gt; </code></pre> <p>This works because ProxyHTMLLinks, by default, is only applied to Content-Type text/html files. However, I don't want to have to hack all calls to header("Location:...") to make this work. I don't mind changing all the calls to header("Location:..."), assuming what I'm changing is correcting a problem, not creating a hack.</p> <p>Lastly, I've done some packet sniffing on the reverse proxy server and discovered that the header("Location:...") sends a HTTP/1.1 302 Not Found to the reverse proxy server, but it doesn't pass this through to the browser requesting redirect.php. When I try one of the "solutions" above, the 302 is then passed from the reverse proxy server to the computer requesting redirect.php. My understanding is that the Location header should go to the browser, and then the browser should request the new location passed back. So it is failing because the 302 doesn't make it to the browser... </p> <p>FYI, I've tried looking at the error logs to see if mod_proxy_html is failing somewhere, but I don't see anything, though I'm open to specific suggestions with regards to logging, since I'm not 100% sure if I'm setting the logging up correctly.</p> <p>Sorry this is so long, just trying to be as specific as possible. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload