Do I need to use lower()?

I recently discovered that there’s a lower() function:

Assuming I need to apply a rule when the URI starts with either wp- or WP-, do I need to use lower() or does the URL Normalization handle this for me automagically?

URL normalization does not change case of URLs, so you should use the lower() function.

2 Likes

Ouch, that puts a damper on that 4,096 character restriction :open_mouth: In practice I have a lot more than wp-, that was just an example.

I don’t suppose there’s a way to do it once in a rule, is there? I know this wouldn’t work, but hopefully it’ll give you an idea of what I’m wishing for:

http.request.uri.path = lower(http.request.uri.path);

(starts_with(http.request.uri.path, "/wp-"))

No method that I’m aware of.
I have something like

(
    lower(http.request.uri.path) contains ".env")
    or (lower(http.request.uri.path) contains "sellers.json")
    or (lower(http.request.uri.path) contains ".php" and not http.host in {"example1.com" "example2.com"})
    or (lower(http.request.uri.path) contains ".htaccess")
    or (lower(http.request.uri.path) contains "ads.txt")
    or (lower(http.request.uri.path) contains "wp-")
    or (lower(http.request.uri.path) contains ".ds_store")
    or (lower(http.request.uri.path) contains ".aws")
    or (lower(http.user_agent) contains "[email protected]")
    or (lower(http.user_agent) contains "netsystemsresearch.com")
    or (lower(http.user_agent) contains "semrushbot")
    or (lower(http.user_agent) contains "webmeup-crawler.com")
    or (lower(http.user_agent) contains "blexbot/1.0")
    or (lower(http.user_agent) contains "bytespider")
    or (lower(http.user_agent) in {"wp_is_mobile"})
    or (not cf.edge.server_port in {80 443}
)
1 Like

FWIW, I’m pretty sure that this technique would have worked, but it wouldn’t actually save any space so it defeats the purpose.

In theory, I could use Transform Rules to create a header with a dynamic value, like so:

(http.request.uri.path contains "*")
[Set dynamic] [lc_uri] = [lower(http.request.uri.path)]

Then I would have a lc_uri variable that’s forced to be lowercase!

But in practice, unless there’s another way that I’m not seeing, the rule expression would look like this:

any(starts_with(http.request.headers["lc_uri"][*], "/wp-"))

which ends up being 10 characters longer than just using lower(http.request.uri.path) :frowning:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.