DeltaRho2K_2167
Feb 15, 2012Nimbostratus
iRule Redirect Question/Help
OK, first, let me apologize for my newbieness to iRules. We just got our LTMs a little over a month ago and I have been thrown in - trial by fire - to get this thing working with multiple applications, using SAN certificates, and now - with the use of iRules. That brings me here to seek out iRule help.
I currently have an iRule in place that checks the incoming http request and if there is no extension and no trailing slash, it adds the trailing slash. The purpose for this is so the IIS on the back-end knows to serve the default document. Without it, the IIS was interpreting the call as a file without an extension, and thus - giving a 404 error. The TrailingSlash_DataList is a data group that contains file extensions called by the web app (.jpg, .png, .html, .js, .jsp, .wsdl, .htm, .aspx, .asmx, .css, etc).
It looks like this --
when HTTP_REQUEST {
set req [HTTP::path]
if { !([matchclass $req ends_with $::TrailingSlash_DataList]) and !($req ends with "/") } {
HTTP::redirect https://[HTTP::host][HTTP::uri]/
}
}
---------------------------------------------------------------
Now, I have been given a new task which I believe should also involve a redirect, but I am not 100% certain.
With the above iRule, if someone calls:
https://www.mydomain.com
Then they are redirected to:
https://www.mydomain.com/
Example 2 - if someone calls:
https://www.mydomain.com/virtualdir
Then they are redirected to:
https://www.mydomain.com/virtualdir/
Now, what I need to happen is when someone calls:
https://www.mydomain.com
Then they would need to be redirected to:
https://www.mydomain.com/virtualdir/
I'm pretty sure this is simple enough -
I need to have the incoming request first check to see if the URL is only the FQDN (without any additional URI - with or without the slashes) - and if so, then I need it to do the redirect to the virtual directory with the trailing slash appended to it.
If the http request contains a URI (like the virtual directory already appended), then I just need to make sure it has that trailing slash appended to it.
I get the logic, and I'm sure it can be done. I'm just not familiar enough with the iRule syntax to put it together. Any help would be appreciated.
(LTM 1600, version 10.2.3)