Forum Discussion
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)
2 Replies
Sort By
- First thing is to remove the $:: prefix from your iRule's reference to the data group(s). This won't work in 10.x+.
- Thanks Aaron -- I'll reply point by point below:
when HTTP_REQUEST { When the request first comes in, we're going to check to see if it's to the FQDN with nothing appended ie https://ac.fsg.amer.csc.com (this condition results in the uri equaling a "/" only) If the uri is only a slash, then we'll redirect to the virtual directory (ACWeb) IIS interprets this "ACWeb/" entry as a request to a directory and loads the default page. if { [HTTP::uri] equals "/" } { HTTP::redirect https://[HTTP::host][HTTP::uri]ACWeb/ } elseif { !([matchclass [HTTP::path] ends_with $::TrailingSlash_DataList]) and !([HTTP::path] ends_with "/") } { If, for some reason, a request is made directly to ACWeb or any other virtual directory (without the slash) then we need to make sure the trailing slash is added in a redirection. HTTP::redirect https://[HTTP::host][HTTP::uri]/ } }
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