I'm trying to set a custom rule within the catalog settings in Facebook's business manager, I want to append UTM tracking to my product URLs and cannot do this from a find and replace regex function. A unique identifier of my product URLs is that they always end with a number 0-9. I'm new to regex and can't figure out how to do this, example below for reference:
Existing product URL:
https://www.example.com/product/12345
https://www.example.com/product/54321
Appended UTM tracking:
https://www.example.com/product/12345?utm_source=askjeeves&utm_medium=cpm
https://www.example.com/product/54321?utm_source=askjeeves&utm_medium=cpm
Any help on how to write a find and replace regular expression to help me append tracking to help me achieve similar to my example above would be much appreciated!
Image below from where I am trying to input this rule:
screen grab in FB business manager catalog custom rule settings
You can do this on your .htaccess. Try the following code into your .htaccess file (Create one if you don't have already) and give me a feedback please.
RewriteEngine On
RewriteRule product/([0-9]+) product/$1?utm_source=askjeeves&utm_medium=cpm [L]
With this code you'll navigate to www.example.com/product/12345 but the system will see full URL which is www.example.com/product/12345?utm_source=askjeeves&utm_medium=cpm
I don't know facebook's find and replace function, but generally a regex should look like this:
(^http.*$)
Then replace with:
$1?utm_source=askjeeves&utm_medium=cpm
You can also try with:
\1?utm_source=askjeeves&utm_medium=cpm
If facebook follows 'normal' regexes, this should Work.
Edit: try these things too, it might Work.
Related
So, I'm trying to crawl a website that has like 7,000 product pages and the link structure is like this:
https://example.com/category/sub-category/numericid-name-of-the-product/
What I'm trying to achieve is to Generate a URL list, the Kimono App has that option, and it actually sections the URL but I'm only offered default value, range, and custom list.
I tried to put in stuff like "/.+/" to match all the chars, but that does not work, I couldn't find any help on that on official kb.
.I know that import.io had that "{alpahnumeric}" for example for different parts of URL so it matches them, is there a way to accomplish that in kimonolabs app?
Try this regex: https://example.com/([^/]+)/([^/]+)/([0-9]+)-([^/]+)
Note: you may need to escape some characters (namely / would be escaped as \/).
Also, I'm not familiar with KimonoLabs, so I don't know if this is what you're looking for exactly. Feel free to clarify.
Explanation
https://example.com/ literally
([^/]+)/ a bunch of not /s, followed by a /
([0-9]+)-([^/]+) Numbers followed by another bunch of not /s
I'm not great with RegEx. I have an Ecommerce site moving from PD Shop to Woocommerce. I need to write 301s for the pages on the old site to redirect to its corresponding page on the new site. The problem is the url structure for site A is completely different than it is for Site B. Rather than doing it manually for thousands of products, I wanted to use RegEx, but I'm not even sure it can be done.
If anyone has any insight on how to pull this off, I'd really appreciate the help. I'd prefer not to do it one link at a time, but I can't see how.
Old links are structured like this:
www.domain.com/shop/item.aspx/item-name/id/
Examples:
www.domain.com/shop/item.aspx/sierra-saw/58/
www.domain.com/shop/item.aspx/duffle-bag-double-strap-olive/2206/
www.domain.com/shop/item.aspx/duffle-bag-side-zipper-black/2207/
New links are structured like this:
www.domain.com/product/item-name/
Examples:
www.domain.com/product/sierra-saw/
www.domain.com/product/double-strap-duffle-bag/
www.domain.com/product/double-strap-duffle-bag/
You should match www.domain.com/shop/item.aspx/([^/]+)/.* and replace it with www.domain.com/product/\1/.
The matching pattern matches url starting with the common root (www.domain.com/shop/item.aspx/), groups their next path fragment (everything up to the next slash) and match the rest of the line.
The replace fragment just repeats the grouped path fragment next to the new common root.
I need to modify URL pattern for IIS Url rewrite module and I could not come up with proper regex pattern.
I already have a rule for front end of the site:
/[event-name] ==> show-event.aspx?event=[event-name]
I need another one for admin login page.
/[event-name]/admin==> admin-login.aspx?event=[event-name]
But IIS gives me this option:
/admin-login/[event-name] ==> admin-login.aspx?event={R1}
How can I change order in this regex pattern for the user friendly url format I want?
^admin-login/([^/]+)/?$
PS: Rewrite Maps is not an option because the event-name will be a parameter and maps are static.
Thanks.
You are using presets rather than empty rules, so at first your options are limited. You can, however, edit your rule and change the pattern to:
^([^/]+)/admin/?$
and keep the rewrite target (admin-login.aspx?event={R:1}). That should do the job.
npinti helped me create a regex to remove the querystring and match the remaining segments from the url /seattle/restaurant/sushi?page=2: "Something like so should yield 3 groups: /(.*?)/(restaurant)/([^?]+).*. Group 1 being seatthe, group 2 being restaurant and group 3 being sushi. If after the last /there is a ?, the regex discards the ? and everything which follows."
I have tried modifying the above to do the same trick on the url /seattle/restaurant?page=2 but I could not get it right. I don't know if there will be af querystring or not or the parameters of the querystring. So I need the flexibility from the regex above which will match and discard the ? and everything which follows.
Your rewriterules may look like:
RewriteRule /([^/]+)/restaurant/([^/]+)$ mynewpage.php?group1=$1&group2=$2 [QSA,NC,L]
Your may search for what QSA, NC, and L mean thanks to the links I provide below.
I'm sorry but your question sound very like "I'm not very good, so can someone do the job for me?". I mean, just look around, you'll get a lot of answer, just get your hands dirty.
Here's the wiki of serverfault.com
The howto's htaccess official guide
The official mod_rewrite guide
And if that's not enough:
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)
This should allow you to match all text prior to the ? and nothing else. It will match everything if no ? is present:
[^?]*
Is that all you need to do? Because /(.*?)/(restaurant)/([^?]+).*. looks like it's designed to do something significantly more complicated.
I want to extract URLs from a webpage these are just URLs by themselves not hyperlinks etc., they are just text. Some examples would be http://www.example.com, http://example.com, www.example.com etc. I am extremely new at regex so I have copy and pasted like 20 expressions online all failed to work. I don't know if I am doing it right or not. Any help would be really appreciated.
I wrote a post on using Regex to locate links within a HTML page (the intent was to use JavaScript to open external links or links to documents such as PDF's etc in a popup window).
The final regex was:
^(?:[./]+)?(?:Assets|https?://(?!(?:www.)?integralist))
The full post is here:
http://www.integralist.co.uk/javascript/regular-expression-to-open-external-links-in-popup-window/
The solution wont be perfect but might help point you in the right direction.
Mark
You're probably not escaping your .s. You need to use \. for each one.
Take a look at strfriend.com. It has a URL example, and represents it graphically.
The example it suggests is:
^((ht|f)tp(s?)://|~/|/)?(\w+:\w+#)?([a-zA-Z]{1}([\w-]+.)+(\w{2,5}))(:\d{1,5})?((/?\w+/)+|/?)(\w+.\w{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?