Score:1

Apache Reverse Proxy rewrite rule for complex URL. "Too Many Redirects" error

br flag

I am trying to configure a reverse proxy to my backend server.

This is my previous configuration which is working.

Define REMOTE_ADDR proxyserver.domain.com

<VirtualHost *:443>
    ProxyRequests Off
    KeepAlive On
    ProxyPreserveHost Off

    RewriteEngine On

    RewriteCond %{HTTP:Upgrade} =websocket
    RewriteRule /prefix/(.*) wss://${REMOTE_ADDR}/prefix/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket
    RewriteRule /prefix/(.*) https://${REMOTE_ADDR}/prefix/$1 [P,L]

    ProxyPass / https://${REMOTE_ADDR}/prefix/ connectiontimeout=5 timeout=300
    ProxyPassReverse / https://${REMOTE_ADDR}/prefix/ 
</VirtualHost>

This is my new configuration.

I want to redirect to:- proxyserver.domain.com/prefix/sen/app/9d12ponf12-2awf2-wafa/sheet/219uaw9dw-waf2/state/analysis

Note: The Remote address will always be the same. I have given an example but this is what it looks like in real as well.

I haven't included SSL information as that is not relevant to my problem.

Define REMOTE_ADDR proxyserver.domain.com

<VirtualHost *:443>
    ProxyRequests Off
    KeepAlive On
    ProxyPreserveHost Off

    RewriteEngine On

    RewriteCond %{HTTP:Upgrade} =websocket
    RewriteRule /prefix/sen/app/9d12ponf12-2awf2-wafa/sheet/219uaw9dw-waf2/state/analysis(.*) wss://${REMOTE_ADDR}/prefix/sen/app/9d12ponf12-2awf2-wafa/sheet/219uaw9dw-waf2/state/analysis$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket
    RewriteRule /prefix/sen/app/9d12ponf12-2awf2-wafa/sheet/219uaw9dw-waf2/state/analysis(.*) https://${REMOTE_ADDR}/prefix/sen/app/9d12ponf12-2awf2-wafa/sheet/219uaw9dw-waf2/state/analysis$1 [P,L]

    ProxyPass / https://${REMOTE_ADDR}/prefix/sen/app/9d12ponf12-2awf2-wafa/sheet/219uaw9dw-waf2/state/analysis connectiontimeout=5 timeout=300

    ProxyPassReverse / https://${REMOTE_ADDR}/prefix/sen/app/9d12ponf12-2awf2-wafa/sheet/219uaw9dw-waf2/state/analysis
</VirtualHost>

It gives 'Too many redirects error'.

I am now stuck and can't figure how to setup rules for a URL like my REMOTE_ADDR.

Any help is appreciated.

Edit- Provided my previous working configuration and also updated my current configuration to show the relation between them.

I've written /analysis$1 and not /analysis/$1 because when I try to access my server directly, some dynamic strings are appended to it, for e.g. /analysis?example

in flag
Configure your backend server properly. It's most probably responsible for the additional redirects.
cn flag
Bob
Try adding a forward slash / to the `ProxyPass.` directive to ensure they slashes are balanced i.e. `ProxyPass / https://${REMOTE_ADDR}/`
Renegade avatar
br flag
I updated the question with more information. Added my previous working configuration and also updated my current one to show where I am currently at.
kz flag
"I've written `/analysis$1` and not `/analysis/$1` because ..., some dynamic strings are appended to it, for e.g. `/analysis?example`" - `$1` would not contain `?example`, but the query string would be appended by default anyway.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.