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.

4
  • Can you let us know more about the current behavior? What error messages you see, what's in the logs? Commented Apr 22, 2015 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. Commented Apr 22, 2015 at 11:00
  • This might help in troubleshooting serverfault.com/questions/248918/… Commented Apr 22, 2015 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. Commented Apr 22, 2015 at 11:07

1 Answer 1

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); 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.