How to Redirect an Ad-Tracking Link
 by Kristi Hagen

How to Redirect an Ad-Tracking Link

  • I have a client who wants to track radio ad responses by using an easy-to-remember domain name that redirects to a specific page with a longer URL on their main site. However I'm having trouble getting the 301 redirect to work. My redirect looks like this;

    redirect 301
    http://MainDomain/landing-page/ redirect 301

    Fyi, in my .htaccess file, located above the redirect, is the following WordPress entry, which redirects requests into the proper subdirectory where the WordPress site is installed:

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /site/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /site/index.php [L]
    # END WordPress

    The problem I'm having is that the 301 redirect resolves to the home page of the MainDomain (instead of the landing page), as specified in the DNS entry at the host's control panel. What am I missing?


First I want to point out that your redirect statements are incorrectly done.

A) - Each Redirect statement must be on one line only, no carrage returns.
B) - Do not mention the domain name at the first part of the statement. Correct format is as follows

redirect 301 /file/pathonly/html

C) In many cases you must generate your redirects before the WordPress statements in your htaccess file. Apache executes these statements in top down order, so we need to do our redirects before WordPress gets ahold of the file requests.

For your specific situation, you may want to use a RewriteRule for this redirect. RewriteRules allow us to do a lot more and apply some logic to how the redirect happens. Here's an example that might work ok for you.

Options +FollowSymLinks
RewriteEngine on
# 301 redirects both www and non-www
RewriteCond %{HTTP_HOST} ^Domain\.com$ [NC]
RewriteRule (.*)$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.Domain\.com$ [NC]
RewriteRule (.*)$1 [R=301,L]

# BEGIN WordPress

RewriteEngine On
RewriteBase /site/
RewriteRule ^in...


Related Articles & Guides