大网数据广告活动
服务器运维问答

How to replace part of a URL request before proxying in apache 2.4?

· 52CE 我爱测

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: <IfMo…

问题原文

原帖链接 · Dark Star1 · CC BY-SA 3.0

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

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

RewriteRule ^lool/https:/alf.mydomain.com\/(.*) lool/https://alf.mydomain.com/$1 [QSA,NE]

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:

RewriteRule ^/lool/https:/(alf\.mydomain\.com/.*) /lool/https://$1 [PT,NE]

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-10-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。