Forum Discussion
Sorin_Rusnac_86
Nimbostratus
Mar 12, 2008iRule to overwrite Page Extension help!
Hi -
Hoping somebody can help me is there a sample or code i can use to overwrite file extenstions on pages is this possible?
For example what I want the iRULE to do is as follows:...
hoolio
Cirrostratus
Mar 12, 2008In addition to nmenant's example, here are a couple more options:
Here is a version which looks for any two to four character extension in all caps and sets it to lower case:
when HTTP_REQUEST {
Get the path (/path/to/file.ext)
Use URI::basename to get the filename and extension (file.ext).
Use getfield to split on the period, getting only the extension (ext).
Prepend a period back to make the string more specific.
set file_extension .[getfield [URI::basename [HTTP::path]] . 2 ]
Log the parsed file extension
log local0. "Original file extension: $file_extension"
For two to four letter capitalized extensions, update the path with the lower case extension.
switch -glob $file_extension {
.[A-Z][A-Z] -
.[A-Z][A-Z][A-Z] -
.[A-Z][A-Z][A-Z][A-Z] {
Set extension to lowercase
set file_extension_lowered [string tolower $file_extension]
Update the path by replacing the original file extension with the lowered case version
HTTP::path [string map "$file_extension $file_extension_lowered" [HTTP::path]]
Log the updated path (this should be removed when you're done testing).
log local0. "Updated path: [string map "$file_extension $file_extension_lowered" [HTTP::path]]"
}
}
}If you only wanted to update .JSP or any other mixed case of .jsp to .jsp, you could simplify the rule:
when HTTP_REQUEST {
HTTP::path [string map -nocase {.jsp .jsp} [HTTP::path]]
}The second of the two options would be more efficient.
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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