Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

URL-uri rewrite problem using Default

Hello,

I am trying to write a simple rule that has worked before in similar circumstances. I need the rule to behave so as three outcomes can take place"
1) If someone types in web.mysite.com that the LTM appends the "/specific" uri.
2) If someone types in web.mysite.com/specific that they go right on to the correct pool
3) If the user types any other misc uri, ie: /whatever, that it redirects/replaces it with the right URL-uri syntax so they can make it to the right pool.

In the rule below, whenever I try to use the "default" option it does redirect them but it strips the jpegs from the page..???? Any ideas on why it is doing this and what a proper rule would look like.

when HTTP_REQUEST {
switch [string tolower [HTTP::uri]] {
"/reaaccom/" {
pool Reaaccom_YGB_80 }
"/" {
HTTP::redirect http://[HTTP::host]/specific/ }
default {
HTTP::redirect http://[HTTP::host]/specific/ }
}
}

///////////////////////////////////////////
I was also trying a rule something along these lines that covers items #1 and #2 but couldn't figure out the wildcard problem described in #3.

when HTTP_REQUEST {
if { [HTTP::uri] == "" || [HTTP::uri] == "/" } {
HTTP::redirect http://[HTTP::host]/specific/


Any input would be highly appreciated.
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
It sounds like the images for the web app aren't under the /specific directory, so when a client makes a request for an image, they're getting redirected to /specific instead of getting the image. What is the path for images?

You can use the -glob flag for switch to use wildcards. Check the switch page on the wiki for details (Click here)

Try searching the forum for more switch examples. Here are a couple: (Click here), (Click here)

Also, you don't need to consider the case where the URI is null (""), as the browser automatically requests "/", when a client types in just the hostname for an app.

Aaron
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
I actually started out using the -glob switch but it came up with the same results. Here is my rule again..as of right now with the -glob switch again.

when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/specific/" {
pool Specific_Pool_80 }
"/" {
HTTP::redirect http://[HTTP::host]/specific/ }
"/*" {
HTTP::redirect http://[HTTP::host]/specifc/ }
}
}


1) Please keep in mind that the url/specific address works fine if I bypass BigIP and/or take out the url. The url/uri is valid. I just don't understand why it strips the jpegs from the pages.

2) If take out the last statement, whether it be a wildcard statement or Default statement then the rule works fine except for monitoring for wildcard URIs. Here is an example that works without the wildcard statements and renders the page correctly.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/reaaccom/" {
pool Reaaccom_YGB_80 }
"/" {
HTTP::redirect http://[HTTP::host]/reaaccom/ }
}
}

Why does adding a wildcard statement (/* or Default) make the LTM strip images even though it does redirect correctly.

Thanks,
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
A few comments.

1. Checking for "/*" is effectively a default state as everything else will match. You can therefore remove the -glob option and use straight string compares (faster). You can also remove the comparison for "/" as that is the same redirect as the default case.

when HTTP_REQUEST {
switch [string tolower [HTTP::uri]] {
"/specific/" {
pool Specific_Pool_80
}
default {
HTTP::redirect http://[HTTP::host]/specific/
}
}
}


I do have question about your default case though. You will be redirecting all URL's that do not equal "/specific/" to "/specific/" (I'm assuming the specifc was a typo...).

How could this possibly work for any content on your site? All URLs will redirect to the same place.

http://www.foo.com/index.html -> http://www.foo.com/specific/
http://www.foo.com/images/file.gif -> http://www.foo.com/specific/
http://www.foo.com/dir1/dir2/file.ext -> http://www.foo.com/specific/


It's pretty obvious why all the images are disappearing as they are getting redirected to the /specific/" URI. Most likely you will want to append the existing URI (or provide some other mapping to carry over the original request URI to the /specific/ directory. Also, you'll likely want the first check to check for a "starts_with" instead of an "equals", so we'll bring back the glob...

when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/specific/*" {
pool Specific_Pool_80
}
default {
HTTP::redirect http://[HTTP::host]/specific[HTTP::uri]
}
}
}


This would yield the following mappings
http://www.foo.com/index.html -> http://www.foo.com/specific/index.html
http://www.foo.com/images/file.gif -> http://www.foo.com/specific/images/file.gif
http://www.foo.com/dir1/dir2/file.ext -> http://www.foo.com/specific/dir1/dir2/file.ext


Another tip, throwing in some log statements will always help figure out what's going on.

-Joe
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
I apprecaite you clearing up how the default works. I am new to these iRules so I am in newbie stage right now. I wanted to explain once more about what I am trying to accomlish.

I need a user to always go to www.foo.com/specific regardless of what they type in, so...
1) www.foo.com > www.foo.com/specific
2) www.foo.com/specific > passes onto specific_pool
3) www.foo.com/anything_else > www.foo.com/specific and then back in to hit pool

Trying to do #3 is what keeps putting me in a loop and cause the images to disappear. Also, I do see what you are saying aobut the images disappearing but I am not seeing that exact path problem when I use HTTPWatch. I will take traces again though and take a better look.

Any other rule examples would be highly appreciated.

Thank you,
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Joe,

The above worked fine with the -glob switch. It's frustrating when you're so close but so far at the same time. Either way, I wanted to answer one of your questions from above as well.

You said:
"I do have question about your default case though. You will be redirecting all URL's that do not equal "/specific/" to "/specific/" (I'm assuming the specifc was a typo...).

How could this possibly work for any content on your site? All URLs will redirect to the same place. "

Answer:
It's just sloppy configuration by the web developer in my opinion. They are using websphere and it has been configured to have the logon(entrance) page at /specific. The box actually has several websites on it with differnt URLs and one http instance. All traffic is coming in on port 80 and the WAS plug-in differentiates, of course by URL/uri path. I hope that answers your question.

Thank you,
0