简体   繁体   English

具有正则表达式重定向的Mod_Proxy

[英]Mod_Proxy with regex redirection

I have a domainA.com which I would like to redirect it to: 我有一个domainA.com,我想将其重定向到:

domainB.com/public.php?service=shorty_relay&id=$1

So the input on the browser should be domainA.com/f7g6f87g and it should make a background redirection to domainB.com/public.php?service=shorty_relay&id=f7g6f87g, but keep the domain on the browser as is. 因此,浏览器上的输入应为domainA.com/f7g6f87g,并且应将后台重定向至domainB.com/public.php?service=shorty_relay&id=f7g6f87g,但应将域保持在浏览器上。

My virtual host lines are: 我的虚拟主机行是:

<VirtualHost *:80>
    ServerAdmin email@address.com
    DocumentRoot /var/www/dir
    ServerName domainA.com
    ServerAlias www.domainA.com
    ProxyPass / https://domainB.com/public.php?service=shorty_relay&id=$1
    ProxyPassMatch ^/([A-Za-z0-9]{4,12})$ https://domainB.com/public.php?service=shorty_relay&id=$1
    ProxyPassReverse / https://domainB.com/public.php?service=shorty_relay&id=$1
    ErrorLog /var/www/dir/error.log
</VirtualHost>

With the current lines Im able to redirect the domainA.com to the root of domainB.com. 使用当前行,我可以将domainA.com重定向到domainB.com的根目录。 But its not what I need. 但这不是我所需要的。 I need the domainA.com to accept only valid ids (?service=shorty_relay& id=$1 ) I know somehow I have to combine this regex so I can allow only valid id. 我需要domainA.com仅接受有效的ID(?service = shorty_relay& id = $ 1 ),我知道以某种方式必须组合此正则表达式,以便仅允许有效的ID。

 ProxyPassMatch ^/([A-Za-z0-9]{4,12})$ https://domainB.com/public.php?service=shorty_relay&id=$1

Any clues how can I make this possible. 任何线索,我怎么能做到这一点。 Im trying to figure this out days now but no luck. 我现在想弄清楚这一点,但没有运气。

Get rid of the ProxyPass line. 摆脱ProxyPass行。 That line works similar to the Redirect directive of mod_alias. 该行的工作方式类似于mod_alias的Redirect指令。 It means anything after the / automatically gets appended to the end of the target URL, excluding query strings. 这表示/自动附加到目标URL的末尾,不包括查询字符串。 That means $1 has no bearing in this directive because you're not using a regular expression to capture a match. 这意味着$1与该指令没有关系,因为您没有使用正则表达式来捕获匹配项。

The only thing you should need is your ProxyPassMatch line: 您唯一需要的是ProxyPassMatch行:

ProxyPassMatch ^/([A-Za-z0-9]{4,12})$ https://domainB.com/public.php?service=shorty_relay&id=$1

Additionally, you don't need to include the query string in the ProxyPassReverse . 此外,您无需在ProxyPassReverse包括查询字符串。 This directive is used to "reverse" map redirects sent from domainB.com to a matching URL in domainA.com. 此伪指令用于“反向”映射从domainB.com发送到domainA.com中匹配URL的重定向。 So this should be enough: 因此,这应该足够了:

ProxyPassReverse / https://domainB.com/public.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM