Forum Discussion

CSA's avatar
CSA
Icon for Nimbostratus rankNimbostratus
Mar 23, 2010

Adding www. before HTTP::host / regexp matching

Hi,

 

 

We have today many websites like www.AA.domain.com where AA is a ccTLD (a country code). We want to have the websites working when users type AA.domain.com.

 

 

In the DNS, AA.domain.com is a CNAME to www.AA.domain.com.

 

 

I want to make the BigIP rewrite AA.domain.com to www.AA.domain.com

 

 

I did this but it doesn't work:

 

 

when HTTP_REQUEST {

 

if { [ string tolower [HTTP::host] ] matches_regex "(?:^\w\w\.domain\.com$)" } {

 

HTTP::redirect "http://www.[HTTP::host]/[HTTP::uri]"

 

}

 

}

 

 

Any idea why it doesn't work ? I don't find many doc about regexp in irules.

 

 

Many thanks,

11 Replies

  • Hi bigbrother,

    I was using tclsh.exe on cygwin for Windows to test with the TCL time command. You could install TCL for Linux and use that. Or you can use an iRule:

    when RULE_INIT {
       log local0. "result: [regexp {(?:^\w\w\.domain\.com$)} aa.domain.com]"
    }
    

    iRules doesn't currently provide the time command, so you can use timing instead if you want to compare the efficiency of different commands:

    http://devcentral.f5.com/wiki/default.aspx/iRules/timing

    Note: iRules are currently based on TCL 8.4. So if you want to use the same library on Centos, install 8.4 (not 8.5).

    Aaron