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

Redirect http to https and www

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

Show longer file names in directory/folder index

If you've ever wanted to show longer file names in your directory listing just create or edit an...

Disable error_log via htaccess

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

What are these htaccess files that keep popping up?

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

When I Upload an htaccess File It Disappears

htaccess & Redirects | Updated March 2026 Your .htaccess file is there. You just can't...



Save 30% on web hosting - Use coupon code Hosting30