How do I Regex this Facebook fbclid? - regex

I migrated a clients site from a Movable Type site with posts that ended in ".php" to a WordPress site that ends in a slash "/". All my 301 redirects are working great but i found out from the client he has links in his websites Facebook page. Those links end in ".php?fbclid=InsertRandomParamsHere". What I need to do is replace the ".php" with "/" and the pages will redirect correctly while maintaining the Facebook tracking parameters at the end.
I've been using a regular expression for the 301 and here is what my regex looks like so far (I'm using Rank Math plugin for redirects):
The Source URL regex is:
^(.*)\.php(.*)
The Destination URL is:
https://www.beachwoodreporter.com/
What I get right now is, for an example link:
http://www.beachwoodreporter.com/music/you_turn_me_on_again.php?fbclid=IwAR37SDAQdPrxMqwHQEY6dcs5rle1Mt0b0WubR9dL8WbaX3zoKNqjW0J84p0
which should redirect to:
http://www.beachwoodreporter.com/music/you_turn_me_on_again/?fbclid=IwAR37SDAQdPrxMqwHQEY6dcs5rle1Mt0b0WubR9dL8WbaX3zoKNqjW0J84p0
is instead redirecting to:
http://www.beachwoodreporter.com/?fbclid=IwAR37SDAQdPrxMqwHQEY6dcs5rle1Mt0b0WubR9dL8WbaX3zoKNqjW0J84p0
so it's basically stripping out the slug portion of the URL:
/music/you_turn_me_on_again/
And the client has many links like this on their Facebook site trying to do one at a time is out of the question. All I need is to replace the ".php" with "/" and it should fix all these problems. Can what I want be done or should I tell the client I can't do it?
Image of the Rank Math regex settings:

Related

URL Redirect with Regex in Google Optimize

I have a website and I'd like to redirect traffic based on a dynamic product ID in the url.
This I'm doing with help of Google Optimize Redirect Test. Setup is based on a Regex to actually fetch the Original page which I want to redirect to an other page.
https://domain.de/en/products/brand/product/a002p00001EuNgzAAF should redirect to https://domain.de/en/our-products/brand/product/a002p00001EuNgzAAF
How can i setup the regex so that I can use the 18 digit product ID as an identifier?
I alread tried to setup a regex like
https:\/\/domain\.de\/en\/products($|\?.*) plus trying to add the expression (\d{18}) but failed in putting it in the right position.

Parse redirection URL

I analyze the URL in a malicious e-mail. I parse the e-mail using BeautifulSoup. I get this URL
https://www.google.com/url?q=http://my.%42%41%44%2e%43%4F&sa=D&usg=AFQjCNGTKogvWUF40RsyeAXrGi6uQrlhoQ
This URL will force Google.com to redirect to http://my.BAD.CO Given a URL like the one above how can I know that the URL will trigger redirect?
I want to get an indication that this is a redirect and I want to get two separate URLs
http://my.BAD.CO and https://www.google.com/url?q=http://5sr0s.%61%6b%68%6f%72%61%62%2e%72%75&sa=D&usg=AFQjCNGTKogvWUF40RsyeAXrGi6uQrlhoQ
where http://my.BAD.CO is an encoded target URL http://my.%42%41%44%2e%43%4F
If the only solution is a custom RegEx like this
(?i)(http|https)://(www.|)google.com/url\?q=(http|https)://(\S+)\&usg=\S+
followed by a call to urllib.parse.unquote will it cover all corner cases?
Are there other ways to redirect besides https://www.google.com/url... ?
I found another way to redirect Here is another way to redirect: via https://www.google.de/url?sa=t&url=
I ended up with a regex
(?i)^(http|https)://(www.|)google.(ac|ad|aero|ae|af|ag|ai|al|am|an|ao|aq|arpa|ar|asia|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|biz|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|cat|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|coop|com|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|info|int|in|io|iq|ir|is|it|je|jm|jobs|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mobi|mo|mp|mq|mr|ms|mt|museum|mu|mv|mw|mx|my|mz|name|na|nc|net|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|travel|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn--0zwm56d|xn--11b5bs3a9aj6g|xn--80akhbyknj4f|xn--9t4b11yi5a|xn--deba0ad|xn--g6w251d|xn--hgbk6aj7f53bba|xn--hlcj6aya9esc7a|xn--jxalpdlp|xn--kgbechtv|xn--zckzah|ye|yt|yu|za|zm|zw)/url\?.+$
or a readable form
(?i)^(http|https)://(www.|)google.(com|de)/url\?.+$
Lot of people considered that the question is not worth an effort of anyone. I got -4 for the question. Some questions appear to be trivial. I still hope that there is a better solution for the problem. I did not find a list of WEB sites allowing redirect of the URL like what google.com/url\?q does
Here is another way to redirect https://www.google.de/url?sa=t&url=

Regular Expression That Will Allow URL Redirect Of All URLs Without A String To Redirect To URL With That String

I have some versioned folders of site files that we are handling through IIS. What I need to do is create a URL Rewrite that will redirect traffic from all requests that don't match the most recent version, TO that most recent version. I'm having a difficult time as RegEx are not my specialty and I have been working on it for the last week.
Here's an example of what I need.
Most recent version:
https://testurl.com/v4/#
Older Versions:
https://testurl.com/#
https://testurl.com/v2/#
https://testurl.com/v3/#
These urls have other routes off of the base as well (ex. https://testurl/v3/#/rout1)
I'm needing a regular expression that will say "Any requested url that is does not contain the /v4/ to REDIRECT to the https://testurl/v4/#
Can someone point me in the right direction?
This regex will capture all domains of the form that you've listed. Capture group 1 will contain the actual route, eg / or /rout1.
/^https\:\/\/testurl\.com(?:\/v\d)?\/#(.*)$/
You can see it illustrated here: http://regexr.com/3fgo8

Facebook Like not appearing , if Url has "/" "%2F" in end

Our website url is ending with slash "/", it get encoded to "%2F". because of this slash facebook like button is not showing on the website.
Eg
Not working url: because in href parameter url has "%2F", but if i remove the "%2f", it starts working. Earlier it was working fine.
https://www.facebook.com/plugins/like.php?action=like&channel_url=https%3A%2F%2Fs-static.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D9%23cb%3Df3e1268db4%26origin%3Dhttps%253A%252F%252Fwww.bcgperspectives.com%252Ff189b4c84c%26domain%3Dwww.bcgperspectives.com%26relation%3Dparent.parent&extended_social_context=false&font=arial&href=https%3A%2F%2Fwww.bcgperspectives.com%2Fcontent%2Fvideos%2Fleadership_paul_deighton_organizing_london_2012_olympics%2F&layout=button_count&locale=en_US&node_type=link&ref=.UCfPf5lBPRI.like&sdk=joey&show_faces=false&width=90
any solution for it.
I can’t get a like button shown on https://developers.facebook.com/docs/reference/plugins/like/ when I input your URL https://www.bcgperspectives.com/content/videos/leadership_paul_deighton_organizing_london_2012_olympics/, no matter whether the trailing slash is there or not.
However, it does get shown if I use http:// instead of https:// in front of your URL – then it works for both versions, the one with the trailing slash and the one without.
An interesting fact though is, that I can not see any information scraped from your page using the debug tool on your URL – doesn’t matter if its the slash or no-slash version or the HTTP vs the HTTPS version, since your server redirects to the HTTPS version with the trailing slash anyway. So that might point to some problem FB’s scraper has with your URL/domain (although no explicit error messages are shown).

Correct escaping of % in the URL with Apache

I have a Django project where I have a search page which takes input through a POST and redirect to /search/<search string>/ and this page renders the result. The percentage sign (%) is used as a wildcard in the search (tes%er returns testuser, tester, etc and the url looks like this then: example.com/search/tes%25er/) and everything works fine with the Django development server. If I manually write tes%er in the url it changes to tes%25er automatically.
Now I'm deploying on an Apache server with mod_wsgi and when my search page redirects to example.com/search/tes%er/ I get the server error: Bad Request. Your browser sent a request that this server could not understand.. If I manually add '25' to the url, like the encoded % sign so it looks like the development server it works fine.
Is there a way for Apache to automatically escape the %-sign and create a url that works, understand % unescaped or do I need to do ugly hacks in my search page that builds the url? (I'd rather not do ugly hacks like this cause then the users can't manually add % to the url and get it to work).
Edit: The code that sends the query from the search page to the search url.
if form.is_valid():
if 'search_user' in request.POST:
q = request.POST['search_user']
return redirect('/search/'+q)
As Ignacio already suggested, you should not redirect to an invalid url. So to answer your question:
you can (or perhaps its better to say 'should') not ask your Apache server to escape your url. The reason you escape your URL is because some characters have another meaning. For example, take a querystring:
somedomain.com/?key=value
If we would want to use a ? or a = in your value you would have a problem because your server would think that you are using operators of your querystring.
The same for the %-symbol. When your apache server sees a %-symbol he thinks he will find an enconded and will try to decode it. If your querystring is %20, apache will translate this to a space, while you meant "wildcard20".
In summary: apache decodes your string, so you dont want him to encode it.
But this does not solve your problem. You can solve your problem by changing your code into the following:
from urllib import urlencode
if form.is_valid():
if 'search_user' in request.POST:
q = request.POST['search_user']
return redirect('/search/?q='+urlencode(q))
In case you wonder: what if my user would type /search/?q=%; in that case he'ld have a problem for he has typed an invalid address.
Hope this helps :-).
Wout