Redirect www.example.com:2096 But Not example.com:2096

I want to redirect:
www.example.com:2096

But not redirect:
example.com:2096

I’ve tried this expression for matching but it doesn’t work (both URIs redirect):
(http.host eq "example.com" and cf.edge.server_port ne 2096)

Requests to the www subdomain will not match that Expression. That Expression will perform the redirect for requests to example.com that aren’t on Port 2096.

2 Likes

So how should I phrase it to work? This also doesn’t work:

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

Why do you keep matching on conditions that you don’t want to match?

You should match the hostname and ports that you want to redirect.

Have you tried:

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

2 Likes

The thing is, I wish to match all URLs except this one:
example.com:2096

This cf.edge.server_port ne 2096 redirects all except:
example.com:2096
*.example.com:2096 <= I wish to exclude this one

How about matching *.example.com:2096 with:

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

1 Like

That works for *.example.com:2096 but not for *example.com.

What is *example.com without the leading dot meant to represent?

1 Like

If you want only the requests to www.example.com on Port 2096 to redirect, you should use:
(http.host eq "www.example.com" and cf.edge.server_port eq 2096)

3 Likes

example.com
*.example.com

Basically, anything that is put before the example.com, including the example.com itself.

That’s a Page Rule syntax and is not applicable to hostname matching in redirect rules.

1 Like

I was not putting that syntax in the redirect rule. I was just trying to explain what needs to be done using a classic wildcard. I need a rule that will perform this:

example.com/ <= redirect
example.com:2096/ <= NOT redirect
*.example.com/ <= redirect
*.example.com:2096/ <= redirect

* here means any subdomain.

Here is the solution, I finally found it after many combinations!

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

This will redirect all mentioned URLs (with any subdomain value) but will not redirect the second URL. In case you wish to exclude a certain subdomain from redirection as well you can add it like this:

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

1 Like

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