Redirect Rule - Match All Except Port and Subdomain

I’m creating a redirect rule to match every URI except these two:

example.com:2096
webmail.example.com

Please take a look. I think everything is correct except the port matching. How to achieve that?

There’s no port option in the dropdown menu, so you have to “Edit Expression” and paste this in:
(http.host contains "example.com" and http.host ne "webmail.example.com" and cf.edge.server_port ne 2096)

1 Like

Thank you, I’ve tried that but it has a problem. This is an SSL port and this happens when I type the following in the browser:

example.com:2096 => 400 Bad Request - The plain HTTP request was sent to HTTPS port
http://example.com:2096 => 400 Bad Request - The plain HTTP request was sent to HTTPS port
https://example.com:2096 => 200 OK

Only when I reload the page it gets redirected to the https version. I have Always Use HTTPS enabled. Most people just type example.com:2096 in the browser so they get an error. How can I solve this?

Why is this not redirecting?

You didn’t mention you’d already tried that.

And the rule has nothing to do with getting a 400 error. The rule only applies when the connection is NOT on Port 4096.

This should be better:

((http.host eq "example.com" and cf.edge.server_port ne 2096) and http.host ne "webmail.example.com")

For the rule to trigger, you don’t need the “contains example.com”, because all requests will have that.

So, you only need two checks:

  1. That it’s NOT example.com on Port 2096 → (http.host eq "example.com" and cf.edge.server_port ne 2096)
  2. That it’s NOT webmail → and http.host ne "webmail.example.com"

You didn’t mention you’d already tried that.

I tried after you suggested it.

((http.host eq "example.com" and cf.edge.server_port ne 2096) and http.host ne "webmail.example.com")

This expression did not solve the 400 error plus now subdomains are not redirecting when I don’t use “contains”:

www.example.com
blog.example.com

This is the solution:

(cf.edge.server_port ne 2096 and http.host ne "webmail.example.com")

Plus the cache was causing the 400 error, so purging solved the issue.

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