Hundreds of hand coded AMZ links....FML

Joined
Mar 27, 2015
Messages
827
Likes
1,476
Degree
3
The site I have purchased has hundreds of hand coded product links spread across hundreds of pages.

Screaming Frog has found all the pages with a link which is great.

Is there a way to automate the replacement of these links to my ID? I have a sinking feeling the answer is no.
 
Of course - massive manipulations of 1s and 0s is the whole point of computers!

#1. If you are using WordPress it's as simple as doing an export of the database and simple find and replace in text software. Hex Fiend for example allows you to open files 100+ GB large (last was tested with 118 GB) and edit them with find/replace, which is the first attempt I would do.

Screen-Shot-2021-03-20-at-12-13-19-PM.png


The caveat is that most text editing software are limited to 1-4GB of files size, however Hex Fiend gets the job done every time since it can update files in the massive GB size without bringing your computer to a grinding halt. Once replaced import the database into the Wordpress and you are good to go.

#2. If your data is within hundreds of standalone pages TextMate allow you to do find and replace (even RegEx), within all files inside a certain sub-directory:

Screen-Shot-2021-03-20-at-12-04-09-PM.png


In the above example I am replacing two newline (\n) characters within one for all files inside the particular sub-directory I choose.

#3. You can also use "grep" and "sed" within the command line to replace the data on the server (make sure to make a backup of before doing ANY of the above three): How to replace a string in multiple files in linux command line

So it really just depends on how the data is stored. How is the data stored?

For a competent person it's 1-2 hour at max worth of work. The longest parts are going to be the backing up, exporting, and re-importing of the database, and spot checking. The actual replacement is like 3 mins MAXIMUM in time.
 
Thanks @CCarter

The site is 11 years old and the previous owner hand coded AMZ shortlinks everywhere to specific products within hundreds of different posts.

So there are literally thousands of links in this format - https://amz.to/sdfd*** - all with different codes and all linking to hundreds of different products.

Finding and replacing seems to be easy enough, the issue as I see it is matching the products - so if the old link is -

https://amzn.to/36ZR*** -->> product a

how do I replace hundreds of unique product links?
 
Last edited by a moderator:
The real problem here is that the previous owner used shortlinks, which means the affiliate ID isn't exposed and can't just do a single mass search and replace on the database to swap to a different one.

Here's an attempt off the top of my head you could consider:

You could use Screaming Frog or any crawler to extract all of the amz.to shortlinks themselves and not just the pages they exist on.

From there you could write a bot to visit one every 30 seconds or so and get the full URL it resolves to and save it, mapping all this as comma separated values in a text file so you can open it in a spread sheet when done.

At this point, you can easily replace their affiliate ID (make sure you check to see if there's more than one) with your own using a Find & Replace in Excel, Google Sheets, Mac Numbers, etc.

Now there's a choice to make. You either fire up a few movies or a TV show, crack open a cold one, and start going page by page (or you hire a VA to do it). You might be able to write some kind of macro to run through the list and do database search and replaces like CCarter has lined out. But for a one-time ordeal it might be faster to just hire a human or two.

Either way you do it, at the end it's going to be critical to do quality assurance. The easiest method would simply be to download the database again and search it for amz.to and amazon.com and see if there's any remaining references to it. Because there's bound to be a few misses.

For anyone reading, I think using Amazon's short links is a very bad move for this reason and many others. It stops you from automating simple processes and creates a mountain out of a mole hill later.
 
Using the https://amzn.to/36ZR*** example, it goes to:

https://www.amazon.com/Wilton-Bright-Standard-Cupcake-300-Count/dp/B00IE70YHA?dchild=1&keywords=yellow+cupcake+liners&qid=1612925497&sr=8-29&linkCode=sl1&tag=ih*****-20&linkId=dd846e52251e3d1e95abd062baab7727&language=en_US&ref_=as_li_ss_tl

^^ in the above I clicked through and it looks like the end URL has the amazon associate of &tag=ih*****-20

--

This is how I would do it, I would get an export of ALL the shortlinks in a text file AND a small MYSQL database (fields: id, shortlink_version, new_link_version). Write a simple programming script that visits each one using curl:

Code:
curl -Ls -o /dev/null -w %{url_effective} https://amzn.to/36ZR***

^^ That outputs:

Code:
https://www.amazon.com/Wilton-Bright-Standard-Cupcake-300-Count/dp/B00IE70YHA?dchild=1&keywords=yellow+cupcake+liners&qid=1612925497&sr=8-29&linkCode=sl1&tag=ih*****-20&linkId=dd846e52251e3d1e95abd062baab7727&language=en_US&ref_=as_li_ss_tl

Then have the script replace all that &tag=ih*****-20 with &tag=MRMedia-2021

And save into the database the following data:

Code:
ID: (auto-increment)
shortlink_version: https://amzn.to/36ZR***
new_link_version: https://www.amazon.com/Wilton-Bright-Standard-Cupcake-300-Count/dp/B00IE70YHA?dchild=1&keywords=yellow+cupcake+liners&qid=1612925497&sr=8-29&linkCode=sl1&tag=MRMedia-2021&linkId=dd846e52251e3d1e95abd062baab7727&language=en_US&ref_=as_li_ss_tl

THEN (don't know if you are using Wordpress or standalone file), I would write a script that does the find and replace within your data.

If it's a Wordpress database, that's makes things really really easy. If they are standalone files, then you'll need the programmer to read inside the sub-directories, whenever it finds an "amzn.to/" link, look into the compiled database, and find the "new_link_version", and replace the shortlink with the newlink.

--

In laymen:

0. Make a backup of everything.​
1. First visit each URL to get the end URL that the redirect goes to.​
2. Replace the old &tag variable to with your version.​
3. Save the NEW url (we are not using shortlinks, long links), in a database that corresponds with the shortlink version.​
4. Write a script that goes through your database or sub-directory files and where ever it finds an old shortlink, it replaced it with the new version of that link.​
5. Save the database and re-import it into MYSQL. (or upload the new files)​
6. Test.​
--
If you go down the VA route, they'll be doing all this manually really, but there is a ton of potential for errors.​
Afterwards I assume you can use Screaming Frog to test that the new end links have your &tag variable OR write your own scraper.​
This is about 1-2 days worth of work for a decent programmer (10-20 hours max billable).​
 
If wordpress there's a way! No need to expend hours doing it.

Some of the answers here got some parts right but missed one key tool: WP CLI

So this is a like Carter pointed out but you can automate the database part.

1- First find ALL the links and get the LONG version. You can do this with screaming frog. The short version is just a 301 redirect. You need to get the final URL.
2- Paste all the links in a google sheet
3- Replace the tags with your tag (basic search and replace)
4- Create a CONCATENATE formula. You need this output: wp search-replace 'OLD URL' 'NEW URL'
5- COPY and PASTE the formula for every link
6- Login via SSH to your wordpress install folder. (Make sure you have WP CLI installed).
7- COPY all the formulas (wp search...) and paste them on the terminal. It will replace all of them. You just need to press enter for the last one. You may do this in batches of 50 / 100 links or whatever

I guess you can do this with a SQL query too.

To find all the links you can use WP CLI too or on the database using regex. http://amzn.to/(.*?)" or similar

EDIT: You should remove the duplicates. On google sheets select the short link column and DATA > Remove Duplicates
 
Last edited:
The search for a programmer begins. Thanks dudes, will update with my final solution.
 
For anyone reading, I think using Amazon's short links is a very bad move for this reason and many others. It stops you from automating simple processes and creates a mountain out of a mole hill later.

Not a bad move when you are the seller. Many buyers are not as smart as MrMedia. They will never know to replace links that don't have tracking ID visible.

This means this seller can continue to reap passive income from a sold website. If it was 7 figure flip then the passive revenue could be in thousands a month.

A lesson for the buyers. Make an agreement with the seller to send you weekly affiliate reports or screenshots as part of post-sale support. The larger the site the more affiliate links you are to miss without help.
 
Dude you don't need to pay people. Grab the plugin by Hekkup. It is buggy but hopefully you can get it to replace all your shortlinks with the long links. Then replace the tags with yours.
 
Pay the $400.

There are hang ups with the plugins and methods mentioned in this thread if you don't do it everyday/aren't fluent.

Simple shit, like stop limits on your server config... prob why carter says download everything I'm guessing. That stupid regex wp plugin is awful for large scans with char exclusions too. Just times out or wrecks an unintended table.

I wasted almost a week stumbling through this exact same thing. Lessoned learned: will negotiate it into the sale next time, now that I know how cumbersome it is. (cakewalk for some, but I can't code my way out of a title tag)
 
Pay the $400.

There are hang ups with the plugins and methods mentioned in this thread if you don't do it everyday/aren't fluent.

Simple shit, like stop limits on your server config... prob why carter says download everything I'm guessing. That stupid regex wp plugin is awful for large scans with char exclusions too. Just times out or wrecks an unintended table.

I wasted almost a week stumbling through this exact same thing. Lessoned learned: will negotiate it into the sale next time, now that I know how cumbersome it is. (cakewalk for some, but I can't code my way out of a title tag)
Looks like I am paying it LOL.

The tech side is beyond me at this point and I have a trusted freelancer on it now so will report back. I hope that one day my programming skillzzz will allow me to be able to understand half the knowledge in this thread.

Thanks boyos.
 
Back