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,
11 Replies
- CSA
Nimbostratus
Answering myself:
when HTTP_REQUEST {
if { [ string tolower [HTTP::host] ] matches_regex {^\w\w\.domain\.com$} } {
HTTP::redirect "http://www.[HTTP::host]"
}
}
Any remarks are welcome if I did something wrong. - 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...
IIUC what you're trying to do is if the host is NOT www.domain.com then do the redirect? Sorry, I'm not sure what regex syntax you're using there, but it doesn't look right... Wouldif {!(string tolower [HTTP::host]] equals "www.domain.com") } {
work just as well? If you just to to match when the host isn't www.domain.com? Using a regex for a simple match seems a bit overkill to me.
H - 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.
Your suggestion of irule will not work. I have many other DNS entries which doesn't look like AA.domain.com. - 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]" } }
Aaron - CSA
Nimbostratus
I don't want anything.domain.com to be redirected to www.anything.domain.com.
Just 2 letters ccTLD. - hoolio
Cirrostratus
Hi Christophe,
The string match command (with the typo fixed) is equivalent to your regex:
% regexp {(?:^\w\w\.domain\.com$)} aa.domain.com
1
% regexp {(?:^\w\w\.domain\.com$)} aaa.domain.com
0
% string match -nocase {[a-z][[a-z].domain.com} aa.domain.com
1
% string match -nocase {[a-z][[a-z].domain.com} aaa.domain.com
0
Aaron - CSA
Nimbostratus
I see...
I guess using string match is faster than the regexp one ?
Thanks for the suggestion BTW... - hoolio
Cirrostratus
Yes, the string match command is more efficient than the regexp by a factor of 10 in a simple tclsh test:
% time {regexp {(?:^\w\w\.domain\.com$)} aa.domain.com} 1000
20 microseconds per iteration
% time {string match -nocase {[a-z][[a-z].domain.com} aa.domain.com} 1000
2 microseconds per iteration
Aaron - 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
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
