apachehttp-redirect

Apache HTTPD as a reverse proxy - how to redirect only URL with hostname onlye, and leave other calls with specific directives


I would like to configure HTTPD as a reverse proxy to redirect only the call for URL with the hostname only (for example: https://site1.com/), and then leave other call with specific directives. Please see below some of the proxy.conf configuration as an example:

<VirtualHost *:443>
ServerName site1.com

ErrorLog /var/log/httpd/site1.com-443-error_log
TransferLog /var/log/httpd/site1.com-443-access_log

...

<Location /wsdata>

    ProxyPass https://site1.com/
    ProxyPassReverse https://site1.com/

    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} websocket [NC]
    RewriteCond %{HTTP:CONNECTION} upgrade [NC]
    RewriteRule .*  "wss://site1.com%{REQUEST_URI}" [P]

<Location /run>
    ProxyPass               https://site1.com/run/
    ProxyPassReverse        https://site1.com/run/?app_name=App1&page_name=Page1/
</Location>

ProxyPass               /        https://site1.com/
ProxyPassReverse        /        https://site1.com/run/?app_name=App1&page_name=Page1/

</VirtualHost>

I appreciate any help to get this configured.


Solution

  • I had to change that directive a little bit. To check if the URL requested is the "root" (/): RewriteCond %{REQUEST_URI} ^/$

    And then the Redirection rule, to include the code 301 for a permanent redirection:

    RewriteRule ^ site1/run/?app_name=App1&page_name=Page1 [R=301,L]

    And now it is working fine.