Apache mod_substitute与条件网址部分

时间:2018-06-08 21:35:49

标签: regex apache reverse-proxy

我是regex的新手。

我正在使用Substitute模式在Apache反向代理上添加联结(包含后端主机名的数值)。

以下是我的9923s交界处的配置:

<Location "/9923s/">
    AddOutputFilterByType INFLATE;SUBSTITUTE text/html text/css
    RequestHeader unset Accept-Encoding
    RequestHeader set Host 10.160.65.96
    Header edit WWW-Authenticate ^Negotiate Negotiate123
    Header edit WWW-Authenticate ^NTLM NTLM123
    ProxyPass  http://10.160.65.96:80/
    ProxyPassReverse  http://10.160.65.96:80/
    ProxyPassReverse /
    ProxyPassReverseCookieDomain "10.160.65.96" "bell.ca"
    ProxyPassReverseCookiePath  "/" "/9923s/"

    Substitute s|\/ev\/|/9923s/ev/|
    Substitute s|"/ev/|"/9923s/ev/|
    Substitute s|'/ev/|'/9923s/ev/|
    Substitute s|"/evimg/"|"/9923s/evimg/"|
    Substitute s|"/evfooter\.html"|"/9923s/evfooter.html"|
    Substitute s|"/dbtree/|"/9923s/dbtree/|
    Substitute s|'/dbtree/|'/9923s/dbtree/|
    Substitute s|\/capture\/|/9923s/capture/|
    Substitute s|"/capture/|"/9923s/capture/|
    Substitute s|'/capture/|'/9923s/capture/|
    Substitute s|\/edgemarcs_v4\/|/9923s/edgemarcs_v4/|
    Substitute s|"/edgemarcs_v4/|"/9923s/edgemarcs_v4/|
    Substitute s|'/edgemarcs_v4/|'/9923s/edgemarcs_v4/|
    Substitute s|\/img\/|/9923s/img/|
    Substitute s|"/img/|"/9923s/img/|
    Substitute s|'/img/|'/9923s/img/|
    Substitute s|\/cgi-bin\/|/9923s/cgi-bin/|
    Substitute s|"/cgi-bin/|"/9923s/cgi-bin/|
    Substitute s|'/cgi-bin/|'/9923s/cgi-bin/|
    Substitute s|\/script\/|/9923s/script/|
    Substitute s|"/script/|"/9923s/script/|
    Substitute s|'/script/|'/9923s/script/|

我使用下面的替换来添加联结号码,因为当Apache引用cgi-bin时它会从URL中删除。

    Substitute s|\/cgi-bin\/|/9923s/cgi-bin/|
    Substitute s|"/cgi-bin/|"/9923s/cgi-bin/|
    Substitute s|'/cgi-bin/|'/9923s/cgi-bin/|

在中间的URL中调用cgi-bin时出现问题。例如,

https://nexuspreprod.qc.bell.ca/9923s/ev/9923s/cgi-bin/ewnsigcap.cgi?id=398

应改为格式化为:

https://nexuspreprod.qc.bell.ca/9923s/ev/cgi-bin/ewnsigcap.cgi?id=398

是否有任何其他方式将结点号9923添加到/ cgi-bin /仅当URL开头时不在中间,如:

https://nexuspreprod.qc.bell.ca/9923s/ev/9923s/cgi-bin/ewnsigcap.cgi?id=398

例如 只有在以下情况下调用/ cgi-bin /后,Apache才会添加9923s联结:

https://nexuspreprod.qc.bell.ca

https://nexuspreprod.qc.bell.ca/cgi-bin/config?page=37

Substitute应该只添加9923,如下所示:

https://nexuspreprod.qc.bell.ca/9923s/cgi-bin/config?page=37

不喜欢这样:

https://nexuspreprod.qc.bell.ca/9923s/ev/9923s/cgi-bin/ewnsigcap.cgi?id=398

0 个答案:

没有答案