Changing URL params to query params - Cloudflare rules - cloudflare

I'm trying to add a Cloudflare URL Rewrite Transform Rule so that users that come to my blog using this link: "https://example.com/myfirstblog" (dynamic path) get redirected to "https://example.com/?blogPage=myfirstblog"
I've tried looking at the docs and using this in the expression editor, but to no avail.
(http.request.uri.path ne "" and not http.request.uri.path contains "/static")

Related

How do I enable query string in Cloudflare page rules?

I want to forward this URL
https://demo.example.com/page1?v=105
to
https://www.example.com/page1
It's not working if I set so:
But if I remove the ?v= part, it works:
Is there any way to include the ?v= part in this page rule?
The rule you mentioned works only for that exact URL: https://demo.example.com/page1?v=105. If it has any additional query parameter or even an additional character, eg https://demo.example.com/page1?v=1050, it won't match the rule.
If you need to use complicated URL matches that require specific query strings, you might need to use bulk redirects or a Cloudflare worker.

htaccess ignore part of query string

It is possible to write a .htaccess rule to ignore part of the query string but still keep it in the url (without redirection)?
i need a way to ignore query string(s) starts with the utm_ like they are absent (invisible to the backend scripts) but still present in the browser URL because the query string will be captured by the JavaScript analytics scripts (thats why solutions with the redirection unacceptable).
lets say i have an url without query string: https://example.com/bla/hello
or with query string: https://example.com/anything?hello=world
then i need to add a query string part utm_source=123 which could be positioned anywhere among the other query string elements
some pages of the site stops working or starts behaving different when im adding a query string to the url for example https://example.com/?utm_source=123 throws 404
if it is possible, could you help me with the rules ?

Apache regex -301 redirects to eradicate duplicates in url path

We are using a CMS that produces URLs of the format www.domain.com/home/help/contact/contact. Here the first occurrence of contact is the directory and the second occurrence is the HTML page itself. These urls are causing issues in the SEO space.
We have implemented canonical tags but the business wants to make sure they don't come across these duplicates in both the search engines and Google analytics, and have asked us to implement a 301 solution on our web server.
My question is we have got a regex to find these matches but I also need the part of the URL before the match. The regex we have is .*?([\w]+)\/\1+ and this returns contact in /home/help/contact/contact. How can I get the /home/help/ path as well so I can redirect to the right page? Can someone help with this please as I am a beginner when it comes to regex?
Since you're able to get contact using a matching group, enclose everything before that inside a matching group as well:
(.*?)(/[\w]+)\2+
I have put the / inside a matching group too, so that you won't get false positives for
/home/some/app/page
this would be \1 ^ ^ found repetition (character p would be matched)

Yii transform url from param/param/param/ to param/param?param

Suppose I have a url like:
site.com/param1/value1/param2/value2/param3/value3/param4/value4
I need to convert this url when a user writes it in url line to:
site.com/param1/value1/param2/value2?param3=value3&param4=value4
P.S. - the number of parameters is variable.
How can I do it?
You need to change the UrlManager Rules according to the situation.
You need to configure the Url manager to handle the first two params as path url and let the rest

Cust google custom search "No Result" string to link

I'm using google CSE in my site. But I want to change the "No Result" string to a link, or redirect the page when no search result.
I tried noResultsString attribute but it accept String only. How can I use HTML Tag like<gcse:searchresults noResultsString="<a src='testSrc'>no-result link</a>"></gcse:searchresults>? Or can I redirect the result page when no-result?
Use JavaScript, then specify names or ids then the functions if there is no results.
Here is an intro tutorial that does not specify an id relating to your case, but is using timers for a redirect http://www.tutorialspoint.com/javascript/javascript_page_redirect.htm