Forum Discussion

destr0yr_22001's avatar
Icon for Nimbostratus rankNimbostratus
Apr 13, 2012

rewrite url with /en/foo to /foo


I'd like to rewrite a number of urls from:








there is no query component.






if { [HTTP::uri] starts_with "/foo" } {











I was going to use HTTP::redirect, however, didnt know if this keeps the meh,bar,rar portion of the uri.






2 Replies

  • Hi,

    I think this should work to strip off the first directory for URIs starting with /foo/. HTTP::path will allow you to rewrite the path as opposed to HTTP::redirect which sends a 302 redirect and updates the URL the client sees.

    when HTTP_REQUEST {
     Check the HTTP path with wildcards
    switch -glob -- [HTTP::path] {
    "/foo/*" {
     Remove /foo from the path by skipping one character and matching after the next /
    HTTP::path [findstr [HTTP::path] / 1]

  • just in case you want redirection.

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            if { [HTTP::uri] starts_with "/foo" } {
                    HTTP::redirect "http://[HTTP::host][string map {"/foo" ""} [HTTP::uri]]"
    [root@ve1023:Active] config  curl -I
    HTTP/1.0 302 Found
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0