iRule Different HTTP Response and lower string

I have the following iRule that works great for 302 to 301 redirects and lowers the uri.

The problem I am running into now that if it returns a status other than 302 (for example a simple 200 return) it does not lowercase the uri.

Here is my code that works great. I would like it to send on any other response, but to lowercase everything.

when HTTP_RESPONSE {
if {[HTTP::status] == 302}{
    HTTP::respond 301 Location "[string tolower [HTTP::header Location]]"
}

}

You could use the HTTP::is_redirect command instead and see if that helps.

Can I ask what your use case is for lowercase uri? If you only care about the uri on the serverside, then you can just do this:

when HTTP_REQUEST {
    HTTP::uri [string tolower [HTTP::uri]]
}

If you need the client to see the lowercase URI in their browser, then you’ll need to issue a redirect in the

HTTP_REQUEST

event. However, you’ll run into issues if it’s not a

GET

request (i.e. if a

POST

is made). In the case of a GET, you could do this:

when HTTP_REQUEST {
    if { ([HTTP::method] equals "GET") && not ([string tolower [HTTP::uri]] equals [HTTP::uri]) } {
        HTTP::redirect [string tolower [HTTP::uri]]
    }
}