Forward / re-write

Dear community,
I’m new to CloudFlare and forwarding/re-writing, so apologies if my question would look to trivial to you.

Problem statement
After migration from WIX to WordPress, there is a need to re-root old blog posts.
Old URL path was /post/, new one: /ua/blog/

Solution found:
Page rule
https://www.domain/post/*
301 redirect to https://www.domain/ua/blog/$1

It works, but consumes a precious limit of 3 free rules

So, I’ve tried to replace it with a Transform Rule but couldn’t make it work :frowning:

What I’ve tried:
Field URI
Operator equals
Value https://www.domain/post/*

Rewrite
Path
Static https://www.domain/ua/blog/*
Query Preserve

It doesn’t work, but I hope you can spot where my mistake might be.
Any advice much appreciated

2 Likes

Please first try everything with a 302 (temporary redirect) and if it works switch to the 301.
If you provide your real Domain/URLs we can debug this on our end.

What exactly does the Browser Console say and what Error-Code are you receiving?

I would not recommend that as transforming will transform the URL behind Cloudflare and not for the Client. Better go with a PageRule, you actually just need one, as it matches the whole pattern. But if you go for the Tranformation rule you must do it exactly the other way around:

https://www.domain/ua/blog/* ==> https://www.domain/post/*
As https://www.domain/post/* is available and https://www.domain/ua/blog/* should serve the content from https://www.domain/post/*

I didn’t think that Transforms used the same syntax as Page Rules. I think it’s a straight replace:

Thanks Martin for the swift response!

the real domain is www.a-hr.pro

example of old URL https://www.a-hr.pro/post/team_elephant
I’m trying to get it forwarded to https://www.a-hr.pro/ua/blog/team_elephant

I tried to replace the asterix * with $1
(rewrite to static https://www.a-hr.pro/ua/blog/$1)
but it also failed

Hope you can help to fix this,
Thanks,
Igor

Hi @sdayman

Thanks for your suggestion

I’ve tried Screenshot by Lightshot
but getting Oops! That page can’t be found.

Does your server log show what URL it was trying to reach?

This should have worked. Please make sure you create this PageRule and place it on top of the list:

URL: https://www.a-hr.pro/post/*
URL Fordward Code: 302
Forwarded to: https://www.a-hr.pro/ua/blog/$1

Save and put it on top of the PageRule list. If it does not work, please provide us with a screenshot of the actual PageRule.

Where can I check this?

OP is trying to use a Transform, not a Page Rule.

Page Rule works perfectly fine Screenshot by Lightshot

I was trying to replace Page rule by Transform Rule

If this doesn’t work, then it’s quite likely you’d need a Biz/Ent plan to do a RegEx text replacement.

It looks like you’ll have to stick with Page Rules. You can get five more for $5/month. Or use .htaccess on your server.

@M4rt1n could you please advise if I can achieve my goal using Transform Rule within a free plan?

My advice since the start of this thread was against the “Transfer” thing as it does not fit your use case. Please do not use a saw to hammer in a nail. … that’s not what it was made for.

If you moved and your site now does have a different baseURL for the BLOG/POSTS, please set up 302/301 redirects to fit your needs and the official google requirements.

If you set up a transform rule, your content will be available from:

  1. https://www.a-hr.pro/post/
  2. https://www.a-hr.pro/ua/blog/

Which google will punish you for. So please set up proper redirects as the content has moved from the one base URL to the other baseURL and redirect your visitors according to you changes. As you mentioned your “valuable” PageRules and that you just have 3 of them (as free user) please still do it that way and later change back to origin and also set up these rules at your origin.

But for the next time you probably want to set up the redirects at Cloudflare to make the redirects happen at the edge and therefore faster.

So for now, please set up an PageRule that redirects your traffic from:

URL: https://www.a-hr.pro/post/*
URL Forward Code: 302 (or if proofen stable “301”)
Forwarded to: https://www.a-hr.pro/ua/blog/$1

And after two weeks or one month you should implement that at your origin and set up a Apache .htaccess rule or a NGINX rule like this, to solve that problem natively but slover as it is getting executed on your origin:

APACHE:

RedirectMatch ^/posts(.*)$ https://www.a-hr.pro/ua/blog/$1

NGINX:

rewrite ^/posts/(.*)$ https://www.a-hr.pro/ua/blog/$1 redirect;

Hope that helps. And please keep in mind that Cloudflare will help you to make that switch faster, but on long term if you care about your 3 free PageRules you will most probably be better with solving that problem natively on your origin and not on Cloudflare. Use Cloudflare when it is important to process things on the Edge fast and if it is not important anymore (1-2 month after) you can fall back to your origin server.

2 Likes