Forum Discussion
Bob_10976
Nimbostratus
Oct 22, 2008Redirecting Only Specfic URL Address
Hello All,
I've been task to setup a iRule that will redirect a url, subsite.mysite.com to mysite.com It actually seems pretty simple but the problem is subsite.mysite.com typically has a trailing site, actually a ton of training sites or services, meaning it looks like subsite.mysite.com/webservice or subsite.mysite.com/application. When I create a redirect iRule it ends up redirecting everything and I only want it to apply if the url matches subsite.mysite.com excatly, anything else shouldn't be redirected. Below is an example of the iRules I attempted but didn't get to work.
Any thoughts or suggestion would be appreciated...
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] equals "subsite.mysite.com ") || ([string tolower [HTTP::host]] equals "www.subsite.mysite.com ")} {
if { ([string tolower [HTTP::host]] equals "subsite.mysite.com ") || ([string tolower [HTTP::host]] equals "www.subsite.mysite.com ") } {
HTTP::respond 301 Location http://mysite.com/
}
}
}
AND
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] equals "subsite.mysite.com ") || ([string tolower [HTTP::host]] equals "www. subsite.mysite.com ")} {
HTTP::respond 301 Location http://mysite.com/
}
}
I did try a trailing slash (/) at the end of "subsite.mysite.com " but that didn't seem to make a difference.
Thanks in advance..
Bob
6 Replies
- dennypayne
Employee
Posted By sklingner on 10/23/2008 11:44 PM
only if there is no uri
There's always a URI. It may be just "/", but [HTTP::uri] should always return a value. So in this case the iRule just needs to look for [HTTP::uri] to be exactly equal to "/".
Denny - dennypayne
Employee
Posted By BobMc on 10/22/2008 12:57 PM
I did try a trailing slash (/) at the end of "subsite.mysite.com " but that didn't seem to make a difference.
That didn't work because subsite.mysite.com is the value of [HTTP::host], as I noted above, the slash would be in [HTTP::uri].
Denny - Bob_10976
Nimbostratus
Hey sorry haven't gotten back sooner...
sklingner...I did try your suggest but it didn't work and by reviewer it i relized I had host and not URI, I changed host to URI and it still didn't work.
When changing it it URI it doesn't do anything, it was as if I didn't put in an iRule at all. But if I changed the uri back to host it would go back to the orginal problem, it rediected everything.
I tried something a bit different, its below, but again it didn't work either, nothing got redirected
when HTTP_REQUEST {
if { ([string tolower [HTTP::uri]] == "subsite.mysite.com") || ([string tolower [HTTP::uri]] == "www.subsite.mysite.com")} {
HTTP::respond 301 Location http://mysite.com/
}
}
I did replace the "==" with "equals" but no difference and I did add the trailing "/" and no change...
Any suggestions?
Thanks
Bob - dennypayne
Employee
Again, the subsite.mysite.com is the host, so what you need is:
(pseudocode - not worrying about syntax here)
when HTTP_REQUEST {
if the [HTTP::host] equals "subsite.mysite.com" or "www.subsite.mysite.com"
and the [HTTP::uri] equals "/"
HTTP::redirect "http://mysite.com/"
}
Denny - Bob_10976
Nimbostratus
Ok, that makes sense....
I'm not very good at the syntax so i'm not 100% that my "and" statement is correct or not, eitherway it still didn't work...
when HTTP_REQUEST {
if { ([string tolower [HTTP::uri]] equals "subsite.mysite.com") || ([string tolower [HTTP::uri]] equals "www.subsite.mysite.com")} {
if { [string tolower [HTTP::uri]] equals "/" } {
HTTP::respond 301 Location http://mysite.com/
}
}
}
Thanks,
Bob - Bob_10976
Nimbostratus
Ok...Sorry...I didn't read your post very good the first time...the host name stays as "host" but the URI is "/"...
I changed my code to as follows and it works like a charm.... Thanks Denny!!
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] == "subsite.mysite.com") || ([string tolower [HTTP::host]] == "www.subsite.mysite.com")} {
if { [string tolower [HTTP::uri]] == "/" } {
HTTP::respond 301 Location http://mysite.com/
}
}
}
Thanks again...
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
