My domain is hosted in a domain name registry cloudflare and the website is hosted in the shopify. We have QR code tagged with each product selling in the shopify. If a customer scan it it will go to mydomain.com?specialCode=123456 and he/she could win a prize. Recently we've developed the sns application on different sub domain sns.mydomain.com. I want to know if we can set up redirect to go to sns.mydomain.com if the url has specialCode attached. Hopefully I can set up a redirect on the name on the cloudflare so we don't need to redirect from client side since shopify doesn't give you access to the server side. Is this possible?

Example mydomain.com?specialCode=123456 => sns.mydomain.com/specialcode=1234

  • Your question is unclear to me. You cant do this in DNS, it has to be done on the web server.
    – davidgo
    Commented Aug 14, 2021 at 19:43
  • You don't say where your DNS is hosted. Your DNS registrar, your DNS host, your main site web host, and your subdomain web host could all be separate, but you'll need to tell us more about how it is all set up if you want better help. Commented Aug 15, 2021 at 0:01
  • @StephenOstermiller I'm pretty sure the website is on Shopify and is integrated with Cloudflare. If this is correct, the solution in my answer works as page rules are supported. support.cloudflare.com/hc/en-us/articles/… Commented Aug 15, 2021 at 0:09
  • Maybe. They only say they are using Cloudflare registrar. They didn't say they are using Cloudflare as CDN. They need to clarify. @MikeCiffone, your answer is really just a stab in the dark. Commented Aug 15, 2021 at 0:13
  • 1
    The domain name is registered @cloudflare and website is hosted in shopify. Sorry for the confusion Commented Aug 15, 2021 at 21:12

1 Answer 1


Cloudflare Page Rules

You can accomplish this using the Page Rules feature. Here is a getting started tutorial by Cloudflare.

What you want to do is map example.com/?parameter1=value1 to subdomain.example.com. The problem is matching the query parameters.

Best route I think is to add a dedicated directory for prizes and use a wildcard. You would just have to create a separate QR code for winners.

mydomain.com/special-prize/* -> sns.mydomain.com/you-lost
mydomain.com/special-prize/w/* -> sns.mydomain.com/you-won

Please be advised wildcards will forward anything after /special-prices/ and /special-prices/w/.

Here's what the Page Rules section looks like:

enter image description here

Checking the prize code in a programmatic way...I think can be done using Query String Sort and you'd need to have an enterprise account. It's designed as a method to control caching so this would be an unorthodox usage to say the least.

You can learn more about that here. You would set up the page rule the same as before just with your winning string in it. I would open a ticket with their technical support.

Without Shopify and CF it would be very simple on a typical server. In Nginx, of the top of my head something like:

location / {
    if ($arg_specialCode = true) {
        return 301 https://sns.mydomain.com$uri$is_args$args;

$is_args is an empty string if there are no arguments, or a ? indicating the start of the query string.

Then $args adds the arguments

$query_string can be used as well, same methodology.

Not the answer you're looking for? Browse other questions tagged or ask your own question.