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.
