Forum Discussion
RegEx assistance for compression URI list
Apologies if this is a basic question.
Ive been asked to configure a client's F5 to compress specific file type only for a particular site. They have a single virtual server that multiple sites are published through (using host headers on the web servers). The virtual server has an http profile that enables content compression for application/json. Ive now been asked to enable compression for *.aspx, *.js and *.css but only for one specific site that is published through the virtual server (dont ask me why, this is what I have been asked to do).
I was hoping to add entries like the following to the URI include list:
*www.sitename.com/*.aspx
*.www.sitename.com/*.js
etc
I cant work out the required format of regular expression. Or am I being dumb on this occasion?
My only other solution would be to create a new virtual server on a seperate IP, but I want to avoid that. Or I guess there are iRules, but I thought this would be simple.
Many thanks in advance.
Ben
1 Reply
- hoolio
Cirrostratus
Hi Ben,
I think the URI list for compression only includes the URI--not the hostname. So you might need to use an iRule for this to selectively enable or disable compression using COMPRESS::enable|COMPRESS::disable. You could test this with just the profile first. The syntax for the URI list is regex, so you could try www\.sitename\com/.*\.aspx and www\.sitename\com/.*\.js. If either of those work, you could try setting the matching to be case insensitive: (?i)www\.sitename\com/.*\.aspx
If you do need an iRule to implement your logic, here's something you could start testing with. You may need to tweak the logic, but hopefully the major pieces are there to start with.when HTTP_REQUEST { Save the path (/path/to/file for www.example.com/path/to/file.ext?param1=value1) for comparison in the response set path [HTTP::path] Save the host set host [string tolower [HTTP::host]] } when HTTP_RESPONSE { Check if this is a text or application/json response switch -glob [string tolower [HTTP::header Content-Type]] { "text/*" - "application/json*" { Parse the filetype from the requested path Split off file.ext from /path/to/file.ext Then use findstr to parse the characters after a period set filetype [string tolower [findstr [URI::basename $path] . 1]] if {$filetype ne "" and $host eq "www.example.com"}{ switch $filetype { aspx - js { Enable compression COMPRESS::enable Exit the iRule so we do not disable compression below return } } } } } If we have not enabled compression above, disable it explicitly here COMPRESS::disable }
Aaron
Recent Discussions
Related Content
* 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
