Page Rule Forwarding Subdomain To Specific Port with Wildcard

ports
wildcard
page-rules

#1

I have followed the instructions at https://community.cloudflare.com/t/page-rules-different-port-special-procedure/15110 but there appears to be a wrinkle in what I am trying to do.

I want traffic that comes in to sub.domain.com to be routed to https://sub.domain.com:8443. I have that working just fine. Thanks to the various helps from this community.

However, I cannot take in any variables to that redirect.

I looked over this article, https://support.cloudflare.com/hc/en-us/articles/200172286-How-do-I-perform-URL-forwarding-or-redirects-with-Cloudflare- , and it appears that is what I want, but I keep getting an error:
Page Rule validation failed: See messages for details. (Code: 1004)

My settings for the rule are:
sub.domain.com
Forwarding URL 302
https://sub.domain.com:8443/$1

That produces the 1004 error.

If I remove the /$1 it works just fine.

Is this a limitation of the free plan? If so, what must I upgrade to make it work?

Any help would be appreciated. Thanks!

Dave


#2

Thanks to Discourse formatting, a * turns the text into italics.

If my hunch is correct, you have a leading * for the Match as well as a trailing *. $1 matches the first wildcard, so you need to use $2 instead to match the trailing wildcard.


#3

The $2 produces the same error 1004.

Thank you though, I should have tried that already.


#4

How about adding Port 443 to the Match URL?


#5

I tried having more than one page rule to accomplish what you are suggesting, but it failed too. The issue is that I want all traffic to come to port 8443, not just stuff that arrives on SSL already. I am not sure that I can accomplish what I want on just the DNS level, I might have to do some juggling on my server too.


#6

If you already enabled “Always Use HTTPS” for your zone…I think that will happen before Page Rules are executed.


#7

I tried 3 different ways.

I tried the always rule, I have put that in place for other sites before.

I tried manually doing that too, basically just manually writing the https into a forward.

I have tried arranging the page rules too, seeing if that would affect it.

I am not sure that I can do it in Cloudflare only, I am not upset about this, just trying to figure the way to do it with the fastest result.

Thanks again for your help.

Dave


#8

I appreciate your help, I am going to move this over to Cloudflare support and see if I can get an answer there. I will post the results here in case anyone else is looking for this.


#9

I think mine is working:

iRetina:~ scott$ curl -I https://www.example.com/test
HTTP/2 301
date: Sat, 09 Feb 2019 17:37:20 GMT
cache-control: max-age=3600
expires: Sat, 09 Feb 2019 18:37:20 GMT
location: https://example.com:8443/test
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 4a681a77ce42540e-LAX

#10

I believe the underlying issue is that Cloudflare believes to recognise a possible redirection loop, because it does not take into account the port number in the redirection URL.

The message in the returned error is clear on that

image

So I believe it is not even about having or not having the variable but the issue is simply the hostname.