How do I do url forwarding with CloudFlare?

Please do the following to forward urls with CloudFlare:

1. Go to the gear icon to open up your settings.
2. Go to the 'PageRule's option.
3. Go to 'Add New Rule' and put in the URL you want to forward in the box.
4. Put the destination URL in the forwarding box.
5. Press the "Add Rule" button.

You would then want to choose the Forwarding Type (choose a 301 redirect or 302 redirect). We generally recommend using 302 redirects so that potential caching issues don't happen with a 301 redirect.

Note:
Forwarding turned on means that you can't set other rules for that URL.

Forwarding examples:

Example forwarding to Google+:

Imagine you have a Google+ profile and you want to make it easy for anyone coming to get to simply by going to a URL like:

    *www.example.com/+

    *example.com/+

This pattern will match:

    http://example.com/+
    http://www.example.com/+
    https://www.example.com/+
    https://blog.example.com/+
    https://www.blog.example.com/+
    Etc...

It will not match:

    http://www.example.com/blog/+  [extra directory before the +]
    http://www.example.com+  [no trailing slash]


Once you have  created the pattern that matches what you want, click the Forwarding toggle. That exposes a field where you can enter the address I want requests forwarded to.

    https://plus.google.com/yourid

If I enter that in the forwarding box and click the Add Rule button within a few seconds any requests that match the pattern I entered will automatically be forwarded with a 302 Redirect to the new URL.

Advanced forwarding options:

If you use a basic redirect, such as forwarding the root domain to www.yourdomain.com,  then you lose anything else in the URL. For example, you could setup the pattern:

    example.com

And have it forward to:

    http://www.example.com

But then if someone entered:

    example.com/some-particular-page.html

Then they'd be redirected to:

    www.example.com

Not where you'd want them to go:

    www.example.com/some-particular-page.html

The solution is to use variables. Each wildcard corresponds to a variable when can be referenced in the forwarding address. The variables are represented by a $ followed by a number. To refer to the first wildcard you'd use $1, to refer to the second wildcard you'd use $2, and so on. To fix the forwarding from the root to www in the above example, you could use the same pattern:

    example.com/*

You'd then setup the following URL for traffic to forward to:

    http://www.example.com/$1

In this case, if someone went to:

    example.com/some-particular-page.html

They'd be redirected to:

    http://www.example.com/some-particular-page.html

 

NOTE: traffic must be passing through CloudFlare for page rules to work, if you are using CloudFlare for DNS only then page rules will not be active.

Have more questions? Submit a request

Comments

Article is closed for comments.