htaccess referral redirect

Setting Up a Referral Redirect With .htaccess

 

A referral redirect (also called a referrer-based redirect) sends visitors to a specific page based on which website they came from. This can be used for targeted landing pages, blocking referrer spam, or routing affiliate traffic.

 

Redirect Visitors From a Specific Site

This sends visitors who clicked a link on referringsite.com to a specific landing page:

RewriteEngine On
RewriteCond %{HTTP_REFERER} referringsite.com [NC]
RewriteRule ^$ /landing-page.html [R=302,L]

 

Block Referrer Spam

To block visitors coming from known spam referrer domains:

RewriteEngine On
RewriteCond %{HTTP_REFERER} spamsite1.com [NC,OR]
RewriteCond %{HTTP_REFERER} spamsite2.com [NC]
RewriteRule .* - [F,L]

 

The [F] flag returns a 403 Forbidden response, blocking them entirely.

 

Note on Reliability

The HTTP Referer header is set by the visitor's browser and is not always present. Some browsers, privacy tools, and VPNs strip or modify the referrer. Do not rely on referrer-based redirects for critical functionality.

  • 146 Users Found This Useful

Was this answer helpful?

Related Articles

What are all these htaccess files?

Understanding .htaccess Files on Your Hosting Account   If you look through your hosting...

When I upload an htaccess file it disappears

Why Your .htaccess File Appears to Disappear After Uploading   On Linux servers, any file...

Create a 410 Redirect for Missing Files

Creating a 410 Gone Redirect for Removed Pages   A 410 response tells search engines that a...

How to create a temporary 302 redirect via htaccess

An easy way to create a temporary redirect from one page to another web page is to use the 302...

Redirecting non-www to www with htaccess

Redirecting non-www to www with .htaccessIf you ever point your www. record to another server...



Save 30% on web hosting - Use coupon code Hosting30