htaccess referral redirect

htaccess & Redirects | Updated 2026

You can use .htaccess to redirect visitors based on the referring URL (the page they came from). This is useful for blocking spam referrers, redirecting traffic from specific sources, or creating landing pages for campaign links.

Block Spam Referrers

Stop fake referral traffic

Add to .htaccess:
RewriteEngine On
RewriteCond %{HTTP_REFERER} spamdomain\.com [NC]
RewriteRule .* - [F,L]

This returns a 403 Forbidden to any visitor referred from spamdomain.com.

01. Redirect Based on Referrer

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

This redirects visitors coming from partnerdomain.com to a specific landing page on your site.

02. Block Multiple Spam Referrers

RewriteEngine On
RewriteCond %{HTTP_REFERER} spam1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} spam2\.com [NC,OR]
RewriteCond %{HTTP_REFERER} spam3\.com [NC]
RewriteRule .* - [F,L]

For the complete .htaccess reference, see .htaccess Guide. For hotlink protection (blocking other sites from embedding your images), use cPanel > Security > Hotlink Protection.

Redirect Help?

Open a Support Ticket

Quick Recap

  1. Use HTTP_REFERER in RewriteCond to match referrers
  2. [F] flag returns 403 Forbidden (block)
  3. [R=302] flag redirects to a different page
  4. Use [NC,OR] to match multiple domains
  5. Hotlink Protection in cPanel for image theft prevention

URL management · Last updated March 2026 · Browse all htaccess articles

  • 146 Users Found This Useful

Was this answer helpful?

Related Articles

How to Create a Temporary 302 Redirect via htaccess

htaccess & Redirects | Updated March 2026 A 302 redirect sends visitors (and search...

Redirect http to https and www

Updated 2026 Quick Answer To redirect HTTP to HTTPS and non-www to www (or vice versa),...

What are all these htaccess files?

Article Updated This article has been consolidated Everything about .htaccess files is in...

Create a 410 Redirect for Missing Files

htaccess & Redirects | Updated 2026 A 410 (Gone) status code tells search engines that a...

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