Forum Discussion

Jerred_Weingart's avatar
Jerred_Weingart
Icon for Nimbostratus rankNimbostratus
Jun 17, 2016

URL rewrite

I need to make an iRule that can rewrite a URL if needed. Actually I just need to add a path between a URL and a filename.

 

website.com/[randomfilename]

 

to

 

website.com/processor/makesstuff/here/[randomfilename]

 

People will have the random file name, but I don't want them to have to write out the whole path. It would be great if it didn't rewrite the the path into the browser as well.

 

Does anyone have an example of something that does this or point me in the right direction. I have seen URL rewrites, but I have to hold onto that incoming file name.

 

I am new to iRules and a bit lost. I do well reverse engineering stuff like this. But don't know enough about iRule syntax to write one that can do this yet.

 

Thanks in advance for any help.

 

-Jerred

 

1 Reply

  • I am making an assumption that the random file name is a file that ends with ".txt". You can change it to anything else you want.

    The following will send a redirect and hence, the browser URL will change:

    when HTTP_REQUEST {
    if { ([HTTP::host] eq "website.com") and ([HTTP::uri] ends_with ".txt") } {
    HTTP::uri /processor/makesstuff/here[HTTP::uri]
    HTTP::respond 301 Location "http://[HTTP::host][HTTP::uri]"
    }
    }
    

    This will change the URL between F5 & Server. However, you would need to provide more information on the exact URL or you can modify the following to suit your needs.

    when HTTP_REQUEST {
    if { ([HTTP::host] eq "website.com") and ([HTTP::uri] ends_with ".txt") } {
    HTTP::uri /processor/makesstuff/here[HTTP::uri]
    pool POOL_ABC
    }
    }
    
    when HTTP_RESPONSE {
    if { [HTTP::header values Location] contains "/processor/makesstuff/here/" } {
    HTTP::header replace Location [string map {"/processor/makesstuff/here/" "/"} [HTTP::header value Location]]
    }
    }