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.
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 TicketQuick Recap
- Use HTTP_REFERER in RewriteCond to match referrers
- [F] flag returns 403 Forbidden (block)
- [R=302] flag redirects to a different page
- Use [NC,OR] to match multiple domains
- Hotlink Protection in cPanel for image theft prevention
URL management · Last updated March 2026 · Browse all htaccess articles
