Jump to content

[SOLVED] mod_subsitute does not seem to work


xxxJimLxxx

Recommended Posts

I have Apache 2.2.9 installed on Solaris 10.

 

I have set Apache up as a reverse proxy to a back-end Content Management System. Apache is running on port 80, the back-end CMS on port 3128.

 

The reverse proxying works fine, but my back-end CMS is producing hard-coded absolute URLs in all the HTML links. These links have the 3128 port hard-coded into them.

 

Consequently when I request www.sample.com/cms the page loads fine. However, all the links in the page are of the form www.sample.com:3128/xxxx

 

Therefore I am using mod_substitute to filter out the port number from the response body.

 

Here is the config from my httpd.conf:

 

# www.sample.com

<VirtualHost *:80>

    ServerAdmin support@sample.com

    DocumentRoot /usr/local/apache2/htdocs

    ServerName www.sample.com

    ErrorLog logs/error_log

    CustomLog logs/access_log common

 

    ProxyRequests Off

    <Proxy *>

      Order deny,allow

      Allow from all

    </Proxy>

 

    <Location /cms>

      ProxyPass http://www.sample.com:3128/cms

      ProxyPassReverse http://www.sample.com:3128/cms

      AddOutputFilterByType SUBSTITUTE text/html

      Substitute s/3128/80/inq

      #Substitute "s|http://www.sample.com:3128|http://www.sample.com|inq"

    </Location>

 

Unfortunately nothing is happening. mod_substitute is not doing its job and re-writing the HTML. Also there are no error messages in error_log.

 

Any ideas?

Link to comment
Share on other sites

Solved!

 

mod_substitute was working fine. The problem lay in the fact that the CMS was gzipping the webpages up in an attempt to speed up its delivery.

 

Most modern browsers will accept gzipped webpages (they use the "Accept-Encoding" header to tell the webserver whether they can accept zipped pages). All I needed to do was switch off the gzipping in the CMS and suddenly mod-substitute sprang into life!

 

(Note: I did try to add the gzip encoding into my mod_substitute directive and it *didn't* work: AddOutputFilterByType SUBSTITUTE text/html application/x-Gzip multipart/x-gzip)

 

Further investigation has shown that other ways of re-writing the HTML output (in addition to mod_substitute) are:

 

1. mod_proxy_html

2. mod_sed

3. mod_ext_filter to invoke some other program to filter the output:

 

# mod_ext_filter directive to define a filter which

# replaces text in the response

ExtFilterDefine external_sed mode=output intype=text/html cmd="/bin/sed s/california/CA/g"

 

<Location />

SetOutputFilter external_sed

</Location>

 

Jim Leek

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.