Forum Discussion
Datagroup Irule matching
I have been trying to make my code match for both host and uri. For example
- :=
-
:=
when HTTP_REQUEST { set locationHttps [class match -value [HTTP::host] equals list-https] set locationHttp [class match -value [HTTP::host] equals list-http] if { $locationHttps ne ""} then { HTTP::respond 301 location "https://$locationHttps[HTTP::uri]" return } if { $locationHttp ne ""} then { HTTP::respond 301 location "http://$locationHttp[HTTP::uri]" return } }
Right now the datagroup file uses:
"www.example.com" := "www.different.com",
"www.example.com/index.aspx" := "beta.example.com",
"www.interesting.com/en" := "app.example.com",
I noticed that everything behind the / either won't work or is taken with the url to the next one so I cannot hard edit behind the /. This was noticable when behind the /abcdef had to change into /abc-def
Is anyone able to help me along the right path to make URI work correctly?
I wasn't sure if I needed a new datagroup specific for the URI so I made one with the more common /en /index entries with empty ""
Every bit of help is welcome!
Based on your code above, only the first datagroup entry will work as you're trying to match [HTTP::host] against the datagroup. Because the next two have a URI in them as well, they will never match.
To do both, you'd need to do something like the below, but i don't have an F5 to test it on at the moment set locationHttps [class match -value [HTTP::host][HTTP::uri] equals list-https]
- ekaleido
Cirrus
And if you do this, remember that [HTTP::uri] will equal / in the absence of anything else.
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