Forum Discussion
Hai_Le_36697
Nimbostratus
Sep 24, 2010redirect wwwX.domain.com to www.domain.com
Hey guys,
I'm pretty new to iRule and this forum has really helped me get to where I am; however, I am stuck and I hope you guys can help. What I would like to do is to extract the domain ...
hoolio
Cirrostratus
Sep 24, 2010Can you provide a bit more detail on your requirements? Do you always want to send a redirect to one hostname (like www.example.com) if the client makes a request with a hostname that isn't www.example.com? Or are there multiple domains that clients could request which resolve to the same virtual server IP address? If there are multiple, do you always want to take the last two domain parts from the request and add www. to the front to form the host in the redirect?
As for the latest example you posted:
You can only check one string against another string using starts_with. So you can change this:
if {[HTTP::host] starts_with "www10." or "www3."} {
to:
if {[HTTP::host] starts_with "www10." or [HTTP::host] starts_with "www3."} {
Or you could use a switch statement instead:
switch -glob [string tolower [HTTP::host]] {
"www3.*" -
"www10.*" {
HTTP::respond 301 Location "http://www.[domain [HTTP::host] 2][HTTP::uri]"
}
}
And you shouldn't need to use concat with the output from the domain command. domain [HTTP::host] 2 should return the last two fields of the domain delineated by periods. So you can change this:
set key "[concat [domain [HTTP::host] 2]]"
HTTP::respond 301 Location "http://www.$key[HTTP::uri]"
to:
HTTP::respond 301 Location "http://www.[domain [HTTP::host] 2][HTTP::uri]"
Aaron
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