3

I have searched quite a lot for a solution and most answers pertain to either proxypass (reverse proxy) or are not relevant.

End users' web browsers are configured to use the Apache proxy server.

I want to redirect all users to an individual web page (on the same server if possible).

Mod_rewrite does not work as it is only triggered when a user tried to visit the proxy server. I want to redirect users trying to access external sites.

The current configuration is simple:

/var/httpd/conf.d/proxy.conf:

<VirtualHost *:*>
    ProxyRequests On
    ProxyVia On

    <Proxy *>
        Order deny,allow
        Deny from all
        Allow from 172.0.0.0/21
    </Proxy>
</VirtualHost>

I was thinking of blocking all requests and then setting a custom error page but cannot find any examples of this working.

kasperd
  • 29,894
  • 16
  • 72
  • 122
ZZ9
  • 838
  • 3
  • 16
  • 47
  • Can you let us know more about the current behavior? What error messages you see, what's in the logs? – ColOfAbRiX Apr 22 '15 at 10:57
  • The proxy works normally at the moment. Users are able to browse the internet etc. Logs show GET requests and not much else. When using mod_rewrite, the rewrite is never triggered unless the user tries to browse to the server. – ZZ9 Apr 22 '15 at 11:00
  • This might help in troubleshooting http://serverfault.com/questions/248918/how-can-i-enable-logging-for-requests-going-through-mod-proxy – ColOfAbRiX Apr 22 '15 at 11:03
  • There is no troubleshooting to do. The current configuration works as apache intended. Im looking for a way to change the configuration to try and redirect. mod_rewrite as far as I know is only triggered when a request is for the server itself and this is the intended use for mod_rewrite. I was hoping there was another obvious method I might be missing or some option on mod_rewrite or mod_proxy I have not found. – ZZ9 Apr 22 '15 at 11:07

1 Answers1

0

I haven't tried output filters with forward proxying, but it works with reverse proxying, so you might want to give the following a try:

#add this outside of any VirtualHost tags
ExtFilterDefine proxiedcontentfilter mode=output cmd="/usr/bin/php /var/www/proxyfilter.php"

#add this in your VirtualHost tag
SetOutputFilter proxiedcontentfilter

In proxyfilter.php have some code like the following:

#!/usr/bin/php
<?php
$html = file_get_contents('php://stdin');
#update this if-condition to match any non-internal hostnames
if ($_SERVER['HTTP_HOST'] != 'www.example.com') {
    header('Location: http://localserver/message_to_display.html');
    $html = '';
}

file_put_contents('php://stdout', $html);
g491
  • 973
  • 5
  • 7