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
}}
16 Replies
- Did you try my rule? I verified that the one I posted works. Your's has several syntax errors.
-Joe - Dave_Horsey_225
Nimbostratus
yes, I copied yours exactly and got that error message when I tried to save. When I removed the elseif statement, it will allow me to save. I probably have an extra space or something and will try to figure it out.
Also, does this make sense?
I am just trying to replace /blog with /blogs/menopauseinsightblog
I though the string had to be the length of the uri replacement string. Also, there will be other pararmeters after the string that I don't want replaced.
i.e. /blog?name=star would turn into /blogs/menopauseinsightblog?name=star - That's odd. I just cut+pasted from the post on v9.2.2 and it loaded fine. I'd try to remove all trailing spaces from your lines and see if that fixes it. As for the substitution, here's a go at it.
when HTTP_REQUEST { if { ([HTTP::uri] starts_with "/blog") and !([HTTP::uri] starts_with "/blogs/menapauseinsightblog") } { HTTP::uri "/blogs/menapauseinsightblog[string range [HTTP::uri] 5 end]" } }
This will replace all uris that start with "/blog" but don't start with "/blogs/menapauseinsightblog" with the new uri appended with character 6 to the end of the original uri.
Keep in mind that this will blanketly replace the strings as such
/blog?user=foo => /blogs/menapauseinsightblog?user=foo
/blogs?user=foo => /blogs/menapauseinsightblogs?user=foo
/bloggin?user=foo => /blogs/menapauseinsightblogsgin?user=foo
Just keep that in mind...
-Joe - Dave_Horsey_225
Nimbostratus
I am currently using 9.05 on the BigIP. Would that impact some of the iRule commands?
BTW Thanks for the help! - Dave_Horsey_225
Nimbostratus
I think I am getting very close....
Here is the iRule so far:
when HTTP_REQUEST {
if { ([HTTP::uri] starts_with "/blog") and
!([HTTP::uri] starts_with "/blogs/menopauseinsight") } {
HTTP::uri "/blogs/menopauseinsight[string range [HTTP::uri] 5 end]"
}
if { [HTTP::uri] contains "blog" } {
HTTP::header replace "Host" "cs.geosign.com"
}
if { [HTTP::uri] contains "Utility" } {
HTTP::header replace "Host" "cs.geosign.com"
}
if { [HTTP::uri] contains "blog" } {
pool MIS-WEB21-CS
} else {
pool MIS-WEB20-4
}
}
The only problem that I have now is that the blog server cs.geosign.com uses style sheets. The other requests get requests that I need to have redirected are:
/Themes/Blogs/marvin3/style/print.css
/Utility/global.js?Version=2.0.60217.2664
/utility/EULA.GIF
These extra get requests don't seem to get caught by my uri contains rules? Therefore, they go to the wrong server. - contains is case sensitive. You'll need to use the "string tolower" command to make your string lower case and then compare against lower case strings
Give this a shot:when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] if { ($uri starts_with "/blog") and !($uri starts_with "/blogs/menopauseinsight") } { HTTP::uri "/blogs/menopauseinsight[string range [HTTP::uri] 5 end]" } if { $uri contains "blog" } { HTTP::header replace "Host" "cs.geosign.com" } if { $uri contains "utility" } { HTTP::header replace "Host" "cs.geosign.com" } if { $uri contains "blog" } { pool MIS-WEB21-CS } else { pool MIS-WEB20-4 } }
-Joe
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
