Forum Discussion
jacob900_39797
Nimbostratus
Mar 12, 2007URL-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.mysi...
Mar 13, 2007
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
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