You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Uw...@amann.com on 2017/02/13 12:08:13 UTC

[users@httpd] FW: mod_substitute only replaces first pattern match

Hi all,

nobody having an idea about my post from Feb 6th?

cu
Uwe

---------8<------- cut ---------8<-------

Hi,

I am trying a reverse proxy server based on apache httpd v2.4 on the most recent release of CentOS:

# httpd -version
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov 14 2016 18:04:44

# uname -a
Linux hostname.domain.tld 3.10.0-514.6.1.el7.x86_64 #1 SMP Wed Jan 18 13:06:36 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)

Within this configuration I have to use mod_substitute to rewrite URLs from some applications.
For this I am using mod_filter with the SUBSTITUTE Filter as follows:

  ProxyRequests Off
  ProxyPass /my-location https://my-server.domain.tld/

  <Location /my-location/>
    ProxyPassReverse    /my-location

    FilterDeclare       AGFILTER

    FilterProvider      AGFILTER SUBSTITUTE "%{resp:Content-Type} =~ m#^text/html#"
    FilterProvider      AGFILTER SUBSTITUTE "%{resp:Content-Type} =~ m#.*/css#"
    FilterProvider      AGFILTER SUBSTITUTE "%{resp:Content-Type} =~ m#.*/json#"
    FilterProvider      AGFILTER SUBSTITUTE "%{resp:Content-Type} =~ m#.*/javascript#"

    FilterChain         AGFILTER

    Substitute          "s#/(css|js|images|management|system|help)/(.*)#/my-location/$1/$2#fi"
  </Location>

It works fine if there is only one occurrence of the search pattern in a line in the html code. This occurrence will be replaced properly.
However, if there are two or more occurrences of the search pattern in one html line, only the first one is replaced. It looks like this example:

<tr><th colspan=3 nowrap></th><th colspan=3 nowrap><a href="overview.epl?hide=1"><img border=0 src="/my-location/images/hide.gif" alt=" Spalte ausblenden"></a> <a href="overview.epl?cl=1&pl=1"><img src="/images/right.gif" border=0 alt=" Spalte nach rechts schieben"></a></th><th colspan=3 nowrap><a href="overview.epl?cl=2&pl=-1"><img src="/images/left.gif" alt=" Spalte nach links schieben" border=0 ></a> <a ....

Here you see: The first one is replaced, the second image URL is the same as before. 

Is this works-as-designed?
Is there any configuration option to make mod_substitute to replace all occurrences of a pattern or is there anything wrong with the configuration? 
I tried several replacement options [fniq] of Substitute, but no change. 

The proxied server runs https. Maybe this is the problem?

Any help appreciated. Thanks a lot!

Mit freundlichen Grüßen / Kind regards
Uwe Poliak 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] FW: mod_substitute only replaces first pattern match

Posted by Uw...@amann.com.
Dear Nick,

I have tried with mod_proxy_html, but the problem with this specific web application is (NAC Management called ARPGUARD), that
several javascripts and json files needs also some replacements because they have hard-coded parts of URLs included. 
I didn't find a way to handle this with mod_proxy_html. 
So I tried with mod_filter including mod_substitute. 

For getting updates etc. better handled I prefer using packages from the official CentOS or EPEL repositories rather than compiling them on my own. 

Regarding the mod_substitute docs I found the following:

f
The f flag causes mod_substitute to flatten the result of a substitution allowing for later substitutions to take place on the boundary of this one. This is the default.

For me this sounds that also the following occurrences of a pattern will be replaced. 

Kind regards Uwe
Uwe

-----Original Message-----
From: Nick Kew [mailto:niq@apache.org] 
Sent: Monday, February 13, 2017 6:32 PM
To: users@httpd.apache.org
Subject: Re: [users@httpd] FW: mod_substitute only replaces first pattern match

On Mon, 2017-02-13 at 12:08 +0000, Uwe.Poliak@amann.com wrote:
> Hi all,
> 
> nobody having an idea about my post from Feb 6th?

What you describe sounds unlikely, but I haven't checked the mod_substitute docs.

I would just point out, there are many alternatives (like mod_line_edit or mod_sed), and the problem you're trying to solve looks like exactly the one for which mod_proxy_html is the smart (markup-aware) solution.

--
Nick Kew


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: [users@httpd] FW: mod_substitute only replaces first pattern match

Posted by Nick Kew <ni...@apache.org>.
On Mon, 2017-02-13 at 12:08 +0000, Uwe.Poliak@amann.com wrote:
> Hi all,
> 
> nobody having an idea about my post from Feb 6th?

What you describe sounds unlikely, but I haven't checked the
mod_substitute docs.

I would just point out, there are many alternatives (like
mod_line_edit or mod_sed), and the problem you're trying
to solve looks like exactly the one for which mod_proxy_html
is the smart (markup-aware) solution.

-- 
Nick Kew


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org