bd94_306725
Oct 06, 2017Altostratus
Irule Regular expression for HTTP redirect
Hello,
i've got a lot of domain like country.mydomain.com
When users write , they are redirect to fr.mydomain.com. To do that i'm using this iRule :
when HTTP_REQUEST {
set host [string tolower [HTTP::host]]
set uri [HTTP::uri]
if {[class match -- $host equals my_datagroup_list]} {
HTTP::respond 301 noserver Location "https://us.mydomain.com${uri}"
}
//elseif ...
else {
switch [string tolower [HTTP::host]] {
"www.mydomain.co.at" { HTTP::respond 301 noserver Location "https://at.mydomain.com${uri}" }
...
...
and hundred of line for each country... that is not really good..
I try to do this with this regex :
What I want : if user write : --> redirect to --> fr.mydomain.com (delete www.) and --> redirect to --> fr.mydomain.com
Actually i've got something like this, but still not working with regex.. can you help me ? 🙂
elseif {${uri} matches_regex {^www\.\\w+\.mydomain\.com} } {
set regexp_result [regexp {view=(\\w+)} $uri viewstring countryDomain]
HTTP::respond 301 noserver Location "https://countryDomain.mydomain.com"
}
Should I replace \w by [a-zA-Z] ?
And i'm not really sur about this line :
set regexp_result [regexp {view=(\\w+)} $uri viewstring countryDomain]
Thanks for your time,
Hugo