I am trying to re-write part of a URL (https://myfirstdomain.com/lool/https:/alf.mydomain.com/service/wopi/files/uuid?query_params
) before the proxying takes place and I have this relevant section in my default SSL vhost:
<IfModule mod_rewrite.c>
RewriteEngine On
LogLevel debug rewrite:trace3
RewriteRule ^lool/https:/alf.mydomain.com\/(.*) lool/https://alf.mydomain.com/$1 [QSA,NE]
</IfModule>
ProxyPass / https://localhost:2323/
ProxyPassReverse / https://localhost:2323/
and I see this in the re-write logs:
applying pattern '^lool/https:/alf.mydomain.com' to uri '/lool/https:/alf.mydomain.com/service/wopi/files/uuid
but on the service that receives this I see that the URL hasn't been re-written. Would be grateful for any clues as to what I am doing wrong. I am essentially trying to add the extra /
that has been removed by a proxy server somewhere in the infrastructure that I do not have access to.
EDIT: in the logs for the backend WOPI service, it sees the request URL un-modified:
Request from 127.0.0.1:42035: GET /lool/https:/alf.mydomain.com/service/wopi/files/uuid
When used in a virtual host context, the
RewriteRule
pattern matches the full URL-path, including the slash prefix (this is only removed in a directory context).Try something like the following instead:
The slash prefix is also required on the substitution when used in a virtual host context, in order to specify a document-root relative URL-path.
I've just extended the captured pattern to include the hostname to save repetition in the substitution.
Literal dots should be escaped in the
RewriteRule
pattern. Whereas slashes (/
) do not need to be escaped.The
QSA
flag is superfluous here since you aren't specifying a query string on the substitution.You may or may not need the
PT
(passthrough
) flag in order to get this picked up by mod_proxy.You should also remove the
<IfModule mod_rewrite.c>
wrapper - unless this is intended to work without mod_rewrite? Otherwise, you'll just mask an errors when mod_rewrite is not available.