Forum Discussion
Dave_Horsey_225
Nimbostratus
Mar 10, 2006Rewrite URL and change pool trouble
I have been working on a irule to rewrite the URL to do the following:
User sends http://www.sitename.com/blog
bigip changes the url to http://blog.sitename.com/ and redirects the request to a different pool
when HTTP_REQUEST {
if { [HTTP::uri] contains "www.sitename.com/blog" } {
HTTP::redirect "http://blog.sitename.com/"
}
if {[HTTP::uri] contains "www.sitename.com/blog" }{
pool default
} else {
pool different
}}
- First thing that sticks out is that the your are combining the host and uri in your "contains" comparison. Also, a redirect sends control back to the browser with a redirect code specifing the new url. Your pool statements after the redirect are not valid because control is never not passed to the backend server due to the redirect. Then the browser will come in with the new uri and it won't match your comparison.
when HTTP_REQUEST { if { "[HTTP::host][HTTP::uri]" starts_with "www.sitename.com/blog" } { HTTP::redirect "http://blog.sitename.com" } }
- Dave_Horsey_225
Nimbostratus
Is it possible to rewrite the URI instead of redirect? (ie. the browser thinks that it is still going to www.sitename.com/blog for the entire session) - Sure is. Check out this blog post on that subject.
- Oops, forgot your second question. If you are just rewriting the URI, I'd include it all in a single rule.
- Dave_Horsey_225
Nimbostratus
Here is what I have right now.... - A couple of things.
if { [HTTP::uri] starts_with "/blog" } { ... }
- Dave_Horsey_225
Nimbostratus
Here is my next attempt, but this won't allow me to save the iRule due to my then and else statements? - Dave_Horsey_225
Nimbostratus
To clarify, I only want the host to be changed if it matches the /blog uri string. - In your HTTP::uri command, you are referencing a variable named "uri". This will be undefined unless you specifically set it with the "set" command. Also, the error for "then" is because there is no "then" reserved word. The "then" is the contents of the enclosed braces.
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/blog" } { HTTP::uri "/blogs/menopauseinsightblog[string range [HTTP::uri] 27 end]" } if { [HTTP::host] eq "www.xxxxxxxxxinsight.com" } { HTTP::header replace "Host" "cs.geoxxxx.com" } elseif { [HTTP::host] eq "xxxxxxxxxinsight.com" } { HTTP::header replace "Host" "cs.geosign.com" } if { [HTTP::uri] contains "/blog" } { pool MIS-WEB21-CS } else { pool MIS-WEB20-4 } }
- Dave_Horsey_225
Nimbostratus
I get the following iRule error....
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