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

Disable error_log via htaccess

Disabling error_log Files via .htaccess   If your error_log file is growing large and...

Redirect http to https and www

To forward a website to use both www. and https:// use the following in an .htaccess file:...

301 Redirect

This code will redirect all visitors who attempt to access the old-url.html page to the...

When I upload an htaccess file it disappears

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

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