1

Okay, I'm not very strong at htaccess. I have a code:

SetEnvIf GEOIP_COUNTRY_CODE US LinkC example1
AddOutputFilterByType SUBSTITUTE text/html
Substitute s/example2/env=LinkC/ni

I'm trying to substitue concrete content in my page. And all text were substituted to env=LinkC, not to example1 as it should to be. Any help?

HBruijn
  • 72,524
  • 21
  • 127
  • 192
cooher
  • 21
  • 1

2 Answers2

1

What you can do is combine Substitute with server side includes. Here is the specific code block that I used

<Location "/css">
    # This specifies the filter sequence
    AddOutputFilterByType SUBSTITUTE;INCLUDES text/css

    # This specifies that SSI should be allowed.
    Options Includes


    ProxyPass "https://fonts.googleapis.com/css"
    # This converts the string I want and replaces them with SSI directives
    Substitute 's|https://fonts.gstatic.com/s/|<!--#echo var="REQUEST_SCHEME" -->://<!--#echo var="HTTP_HOST" -->/s/|'
</Location>

To help with figuring out what variables you have available you can temporarily do this

Substitute 's|https://fonts.gstatic.com/s/|<!--#printenv -->/s/|'

I used this in my Google Fonts Proxy image [sources].

0

mod_substitute doesn't do this. The replacement strings are static, or are back references to the search string regular expression, not request-specific.

Take a look at the server side includes feature instead:

https://httpd.apache.org/docs/current/howto/ssi.html

Pages utilizing this feature can be simple templates which can have request-based substitutions and incorporate some simple conditional logic.

Jonah Benton
  • 1,242
  • 7
  • 13