Manual Chapter : Referencing an External File from within an iRule

Applies To:

Show Versions Show Versions


  • 11.5.0

BIG-IP Analytics

  • 11.5.0


  • 11.5.0


  • 11.5.0


  • 11.5.0

BIG-IP Link Controller

  • 11.5.0


  • 11.5.0


  • 11.5.0


  • 11.5.0
Manual Chapter

Overview: Referencing an external file from an iRule

Using the BIG-IP Configuration utility or tmsh, you can import a file or URL from another system to the BIG-IP system, with content that you want an iRule to return to a client, based on some iRule event. Possible uses for this feature are:

  • To send a web page other than the page that the client requested. For example, you might want the system to send a maintenance page instead of the requested page.
  • To send an image.
  • To use a file as a template and modify the file in the iRule before sending the file.
  • To download policy information from an external server and merge that data with a locally-stored policy.

The file that an iRule accesses is known as an iFile, and can be any type of file, such as a binary file or a text file. These files are read-only files.

This example shows an iRule that references an iFile named ifileURL, in partition Common:

ltm rule ifile_rule { when HTTP_RESPONSE { # return a list of iFiles in all partitions set listifiles [ifile listall] log local0. "list of ifiles: $listifiles" # return the attributes of an iFile specified array set array_attributes [ifile attributes "/Common/ifileURL"] foreach {array attr} [array get array_attributes ] { log local0. "$array : $attr" } # serve an iFile when http status is 404. set file [ifile get "Common/ifileURL"] log local0. "file: $ifile" if { [HTTP::status] equals "404" } { HTTP:Respond 200 ifile "/Common/ifileURL" } } }

iRule commands for iFiles

This list shows the commands available for referencing an iFile within an iRule. All of these commands return a string, except for the command [ifile attributes IFILENAME], which returns an array.

Available iRule commands for referencing an iFile

[ifile get IFILENAME] [ifile listall] [ifile attributes IFILENAME] [ifile size IFILENAME] [ifile last_updated_by IFILENAME] [ifile last_update_time IFILENAME] [ifile revision IFILENAME] [ifile checksum IFILENAME] [ifile attributes IFILENAME]

Task summary

You can import an existing file to the BIG-IP system, create an iFile that is based on the imported file, and then write an iRule that returns the content of that file to a client system, based on an iRule event.

Task list

Importing a file to the BIG-IP system

As a prerequisite, the file you want to import must reside on the BIG-IP system you specify.
You can import a file from another system onto the BIG-IP system, as the first step in writing an iRule that references that file.
  1. On the Main tab, click System > File Management > iFile List > Import.
  2. For the File Name setting, click Browse. The system opens a browse window so you can locate the file that you want to import to the BIG-IP system.
  3. Browse for the file and click Open. The name of the file you select appears in the File Name setting.
  4. In the Name field, type a new name for the file, such as 1k.html. The new file name appears in the list of imported files.
  5. Click Import.
The result of this task is that the file you selected now resides on the BIG-IP system.

Creating an iFile

As a prerequisite, ensure that the current administrative partition is set to the partition in which you want the iFile to reside.
You perform this task to create an iFile that you can then reference in an iRule.
  1. On the Main tab, click Local Traffic > iRules > iFile List.
  2. Click Create.
  3. In the Name field, type a new name for the iFile, such as ifileURL.
  4. From the File Name list, select the name of the imported file object, such as 1k.html.
  5. Click Finished. The new iFile appears in the list of iFiles.
The result of this task is that you now have a file that an iRule can reference.

Writing an iRule that references an iFile

You perform this task to create an iRule that references an iFile.
Note: If the iFile resides in partition /Common, then specifying the partition when referencing the iFile is optional. If the iFile resides in a partition other than /Common, such as /Partition_A, you must include the partition name in the iFile path name within the iRule.
  1. On the Main tab, click Local Traffic > iRules. The iRule List screen opens, displaying any existing iRules.
  2. Click Create. The New iRule screen opens.
  3. In the Name field, type a name between 1 and 31 characters, such as my_iRule.
  4. In the Definition field, type the syntax for the iRule using Tool Command Language (Tcl) syntax. For complete and detailed information iRules syntax, see the F5 Networks DevCentral web site (
  5. Click Finished. The new iRule appears in the list of iRules on the system.

Implementation result

You now have an iRule that accesses a file on the BIG-IPsystem, based on a particular iRule event.