Forum Discussion
CAMES_13251
Jun 20, 2011Nimbostratus
Remove URI if it doesn't match my options?
Hi All,
I'm quite new to irules, and can't get something working that should be quite simple.
What I am trying to do is redirect the request based on a couple of key words in the U...
CAMES_13251
Jul 26, 2011Nimbostratus
Thanks for the reply, Ryan.
To give you the background, what I am trying to do is redirect based on the presence of a couple of keywords in the URI, but when it does get redirected, to remove the keyword part but preserve the rest of the URI after the redirection.
For example, www.test.com/test1/hello would redirect to www.testone.com/hello because test1 is a keyword. I haven't even got to the part where I remove the keyword from the URI though, I can't even preserve the URI after the redirection so far! With the code below, it doesn't append the URI to the new site (www.test.com/test1/hello just goes to www.testone.com, for example).
I also added code to ignore the CSS file as the formatting was wrong without it, so I'm not sure if that breaks anything.
If a keyword is not in the URI, it should not redirect at all, but should remove the URI so they don't get a "not found" for things that don't exist (hence the default bit and the CSS exception).
Here's my code:
when HTTP_REQUEST {
Check the requested URI set to lowercase
switch -glob "[string tolower [HTTP::uri]]" {
"/test1*" {
Requested URI started with /test1
HTTP::respond 301 Location "http://www.testone.com[HTTP::uri]"
}
"/test2*" {
Requested URI started with /test2
HTTP::respond 301 Location "http://www.testtwo.com[HTTP::uri]"
}
"/style.css*" {
return
}
default {
HTTP::uri "/"
}
}
}
Thanks for any advice!
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