How to set up an affiliate link redirects and replace links on WordPress

Andrey Novoselov Andrey Novoselov
Reading time:  10  min.

Affiliate links are one of the most effective tools for selling flight tickets, hotels, tours, and other services and goods on a travel-blog. There are several solutions for conveniently managing a great number of the affiliate links on a travel website. On this page, we have considered how to set up affiliate link redirects on the most popular CMS for the travel websites — WordPress. Here you also will find details about convenient massive link replacement.

How to set up affiliate link redirects and replace affiliate links on WordPress

The problem with affiliate links

Over time, the number of the links on a site increases to an amount that could be hardly managed manually. The trouble begins with even small-scale projects when the replacement of the old links with new ones is required — for example, in the case of redirecting traffic from old links to new pages. Manual replacement is the backbreaking labor.

In addition to difficulties maintaining the links, a large number of external links can influence the search engines’ treatment of your project. Converting links to inline tag <nofollow> partially solves the problem with search engines but doesn’t simplify the maintenance of the hundreds of links on your site.


The fundamental solution to the problem is to use a link management system to fix the links via a redirect.

With tools for creating and managing links, you can replace a target URL in just a few clicks. In the end, the link in your article still has the same format, but the user goes not to as before, but to, for example.

There are several ways to manage affiliate links. We have collected the most important ones below and reviewed them in detail.

What is the redirection of links?

Redirecting is referring users to another page. When clicking a link such as, the user lands on the affiliate page — for example,

Redirection is necessary not only for managing links in articles but also for eliminating doubling, 404 errors, and domain name slake. In the last case, you can save the site’s position in SERP and traffic from the previous domain name.

Redirect algorithms are very simple:

  1. The user clicks a link.
  2. The server or browser processes the data.
  3. The user is automatically redirected to the defined link in cases where there is redirect.

This process is automatic and instantaneous.

Redirects 301, 302, 307

Ten HTTP codes for redirects exist, but only three of them are in demand. Let’s look at their key points.

  • 301: A constant redirect indicating that the transfer is permanent. This code usually means the site’s redirected while moving to another domain.
  • 302: A temporary redirect. It indicates that the site move is temporary. This is perfect for the redirecting affiliate links.
  • 307: A Temporary redirect. The implementation of the code doesn’t allow the query method (GET/POST) to change. In practice, codes 307 and 302 are identical.

How to set up a link redirection

Rookies could hardly deal with putting redirects into effect. That’s why we have reviewed the basic methods for redirecting links.

Services for truncating links

These services help redirect links without changing your settings or installing software. You can just use the services’ web-based versions:

The examples above are simple services for shortening links. These redirects don’t solve all your problems but do allow you to package the links in the same format and learn more statistics.

If you’re working with programs through Travelpayouts and your goal is to create beautiful, short affiliate links, it’s not necessary to use third-party services. You can create a short URL without leaving your Travelpayouts’ account. Simply open the «Link Generator» tool on the page of the selected program and fill in the required fields. The generator will return a short version of the affiliate link with the name of the brand included.

HTML, JS, and PHP Scripts

Redirection that is done with the aid of PHP scripts puts additional strain on the server. However, it is preferable when you have a great number of pages. This kind of redirection is performed on the server level.

A redirect using JavaScript operates on the browser level. The full load in the browser is required to make it work, which is why this method is slower than a PHP redirect. It is sometimes used for redirections with a delay. Also, JS redirect doesn’t work unless you switch on a JavaScript function.

Redirection via an HTML code is similar to JS and operates on the browser level, so it proceeds slower than redirects on the server level.

WordPress plugins

If the website is based on WordPress, then it is better to use third-party plugins. They help to shorten the link and to create the link on your domain, as well as manage redirects and collect statistics.

Below we look at each of the redirects’ methods and give the valid sample.

The top three URL shorteners for shortening long links


Google’s service for link reduction has always demonstrated a pattern of consistent quality. You can proceed with any actions in just a few clicks. The interface is intuitive, easy to use, and minimalistic. You should authorize the statistics, where you can learn

  • The number of hops
  • Citations for the links on the web
  • The map of popularity in different countries
  • Platforms and browsers viewer use the most often

Unfortunately, as of April 13, 2018, only old users can use this service. Google will stop running this service on March 30, 2019.


Bitly is one of the leading services for link reduction. You can name short links and see the detailed statistics. The service is free, but a paid version is available. The paid version widens the functionality sufficiently. With it, you will get

  • Detailed analyses
  • A link builder
  • Flexible corporative settings
  • Extensive technical support
  • A personal manager
  1. is a simple service with a minimal set of options. It allows you to create a very short link starting with

The service is available in seven languages. According to user reviews, this site is one of the most trusted services, always works always well, and hasn’t had much downtime in the past.

Popular plugins for WordPress

Design plugins offer a similar mechanism but include various extra functions. You will get a shortened link on your domain as a result. Plugins provide fast link redirection on WordPress and a convenient way to manage the links. For example, you can replace the target URL.

Thirsty Affiliates Affiliate Link Manager

Thirsty Affiliates Affiliate Link Manager

Thirsty Affiliates Affiliate Link Manager is a high-quality plugin claiming to be a helpful assistant for bloggers who reap returns from affiliate programs. Its 20,000 active downloads and good ratings prove the quality and popularity of the plugin. The users have mentioned the following facts in their reviews:

  • Easy to use due to the visual editor
  • Increased experience with managing links
  • Safe redirect via the 301, 302, and 307 codes
  • Add images to the affiliate links
  • Statistics and reports

A paid version (PRO version) for one, five, or any number of sites is available.

Shortlinks by Pretty Links

Shortlinks by Pretty Links

Shortlinks by Pretty Links is a multi-functional plugin for managing links on WordPress that has already collected 200,000 active installations. With the plugin, you can create your own links with the redirection to the target URL from your website’s administrative panel. You can also manage the links that have been previously created. There is no need to know how to code to work with this service.

The paid version main options:

  • 301, 302, and 307 redirects
  • Link categorization
  • Statistics graphics
  • Data exporting in .csv format

How to install

You can download the archive from the official library or install the plugin via your website’s administrative panel. Type the plugin’s name in the search bar and click Install:

How to Install

A new block will appear in the administration menu after plugin activation:


Links creating

Hop to the “Add Link” section: The editor will open. Set a short link and a target URL:

Links Creating

In the redirection area, choose the basic parameters—in this case, 302. Click Create at the bottom of the page to save the link.

Then you can use the link — in this case, — anywhere you want. The user will hop to the page you’ve set after he clicks the link — 1 in our example.

Managing links

All the links are accumulated on the plugin’s main page. Here you also see the basic statistics, such as the total number of clicks.

Managing Links

You can change your target URL as needed—just choose the link you’re interested in and set a new Target URL in the opened window. Then the previous link will lead you to a new page, and you don’t have to replace the link on your site. On the Clicks page, more data on the clicks is available.


Expanded opportunities

Everything that is outlined above is available in the free version. The plugin’s paid version, Pretty Link Pro, is also available. The following functions are available with the paid version:

  • Auto-replacement of links on the website
  • Auto-deployment of links for the specified words
  • Redirect based on the user’s country
  • A/B testing
  • Other functions

The paid license costs $57 a year for one website. You can get a 10% discount with the coupon code 10OFF.

Easy Affiliate Links

Easy Affiliate Links

Easy Affiliate Links is an alternative to Shortlinks by Pretty Links. The plugin is focused on the Amazon affiliate program but can be used for any other links. More than 10,000 people use Easy Affiliate Links for link reduction to date.

The plugin’s key points are

  • An intuitive interface
  • Statistics
  • Link categorization
  • Link importing and exporting to .XML

The developers also offer extra paid options, such as detailed statistics. Click location, A/B testing, and “broken” link tracking are currently under development.

Shortlinks for Jetpack Sharing Buttons

Shortlinks for Jetpack Sharing Buttons

Shortlinks for Jetpack Sharing Buttons is a plugin for redirecting on WordPress with a full set of functions for link reduction. It is mostly used as an addition to the Jetpack plugin to increase its options. You can track the statistics via a free plugin, Google Analytics by Yoast.

The developers note that Shortlinks for Jetpack is currently under development, so errors are possible. However, they are usually corrected very quickly. Because this project has open-source software, the issues are sent to GitHub.

Link redirection via PHP-script and JavaScript

As we have indicated, PHP redirects work faster than JS, making them more popular among webmasters. To realize a simple redirection, add the following code to the index.php file:

$links = parse_ini_file('shortlinks.ini'); 
if(isset($_GET['l']) && array_key_exists($_GET['l'], $links)){
     header('Location: ' . $links[$_GET['l']]);
} else{
     header('HTTP/1.0 404 Not Found');
     echo 'Unknown link.'; 

There is no control panel in this case. All the main links are put in the shortlinks.ini file manually. Note that you should create this file manually too. Then you can write this code inside the file:

Aviasales =

As a result, you’ll get the links in format.

This sample demonstrates the common redirection of a link in WordPress via a PHP script.

Redirection via JavaScript is done by a code that is placed between the tags <head> and </head> on the appropriate page. To do so, you should use plugins, such as Per page add to head.

Here is a sample of the simple code for JavaScript redirection:

  window.location.href = "";

Note that it is impossible to build in the independent JavaScript code between the tags <head> and </head> if there is a unified design without any third-party plugins. That’s why you have to create the separate template for every page or to use an additional plugin to implement the code.

The best solution for the WordPress sites

It is only half of the story to create the link with a redirect. Then you’ll have to manage the link – track statistics and change target URLs. The turnkey solutions look better than common PHP/JS scripts as they allow you to do more with less effort.

Except the link managing that you’ve already had, you can have one more problem – implementing new links on the site or replacing the old ones.

For example, you have been doing the travel blog for 4 years already but have just found out the special plugins for links. Then you have to solve the problem – replacing hundreds or even thousands of old links.

Plugin Pretty Link in the enhanced version is a versatile solution. In addition to redirection, it has extra auto-options:

  • Replace the old links for the links in a new format.
  • Set the links for the words that haven’t had them before.

This plugin is great but not free. You can solve this problem just fine using two plugins – PrettyLink (free version) and a free plugin for the old links’ replacement on the site.

How to make the total replacement of the old links on the website?

Important! You should always create a backup copy of your site’s database before starting the replacement!

The Plugin BetterSearchReplace will be helpful for the auto-replacement of the old links for the new ones, as well as with the positioning of references to the words. More than 50,000 active installations are currently being used. Its main options are as follows:

  • A massive replacement of the old links.
  • Selecting the separate tables to work.
  • An “idle” start to look through the areas that are going to be updated.

This plugin will help you to update the old links or to position the new ones to the words. For example, you can put in the search the words “air tickets” and point the following in the area for replacement:

<a href="">flight ticket</a>

This method has some alternatives. You can use either identical plugins or make changes in MySQL database via host control panel. One more opportunity is to use the PHP-script “Replace DB version 3.1.0” that is available here. It is compatible with both WordPress sites and the other popular CMS.

While preparing this material we have tested some widespread solutions, including plugin URL ShortenerbyMyThemeShop. The promising description claims that you’ll get tools for redirecting, managing, and implementing massive replacements for free. It could be a great alternative to the paid PrettyLinkPro, yet it does not work in practice.

Should you redirect the affiliate links?

You should redirect links to manage your own project in the best way. The more usable the tool you select, the more efficient your work will be. The link managing systems provide more options than the manual inclusion. For example, you can make A/B testing of the new niche in some clicks via the target URLs replacement.

Certainly, you can do manually all the plugins and scripts’ settings. The question is one of the greater convenience in your work and your opportunities.

While using the redirect, you should note that if the user cannot understand the essence of the redirection, he/she could be annoyed. That’s why you should make fine and clear shortenings, appeasing the user with every little detail about their destination when they are ready to click.

Share your questions and experiences in redirection and managing the affiliate links on the site in the comments section.

15 AI Tools Tackling Travel Bloggers' Top Challenges