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...

Redirecting non-www to www with htaccess

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

Redirect http to https and www

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

htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

To solve “.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable” follow...

What are these htaccess files that keep popping up?

htaccess & Redirects | Updated 2026 If you keep finding .htaccess files appearing in your...



Save 30% on web hosting - Use coupon code Hosting30