Forum Discussion
CSA
Nimbostratus
Mar 23, 2010Adding 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,
- CSA
Nimbostratus
Answering myself: - Hamish
Cirrocumulus
Hmm... Well, leaving aside the fact that you shouldn't have it as a CNAME (Because as a domain you'll have an SOA record plus maybe an MX record, and you shouldn't have any other records if you have a CNAME record). Best create it as an A record instead... Anyway...if {!(string tolower [HTTP::host]] equals "www.domain.com") } {
- CSA
Nimbostratus
Hmm, I don't get what you mean when you say I shouldn't define CNAMEs. I don't have SOA or MX records on these entries, they are all in the domain.com zone, just standard A entries. - hoolio
Cirrostratus
How about a string pattern then?when HTTP_REQUEST { if {not [string match -nocase {[a-z][[a-z][.domain.com} [HTTP::host]] } { HTTP::redirect "http://www.[HTTP::host]/[HTTP::uri]" } }
- CSA
Nimbostratus
I don't want anything.domain.com to be redirected to www.anything.domain.com. - hoolio
Cirrostratus
Hi Christophe, - CSA
Nimbostratus
I see... - hoolio
Cirrostratus
Yes, the string match command is more efficient than the regexp by a factor of 10 in a simple tclsh test: - CSA
Nimbostratus
Thanks! - Andrea_Arquint
Nimbostratus
Hi allHow do you run this command?
% regexp {(?:^\w\w\.domain\.com$)} aa.domain.com
Is this run on a linux bash shell???
I'm using centos and I did install "regexp" but there is no binary to execute???
Thanx for help
bb
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects