Referrer-based htaccess redirection

We want users from a particular website to use our services. Is there a way to redirect all traffic that does not come from a particular referrer to a website of our choice via htaccess?

In addition, this is only for the first page. Therefore, if they get to our site, they are going to view the new page, and their referrer for the new page will apparently be the site on which they are already located.

Thanks!

+6
source share
2 answers

Try adding this to your htaccess file in your document root:

RewriteEngine On RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC] RewriteRule ^/?first-page.html$ http://the-website-of-your-choosing.com/ [L,R] 

You can also have your own domain added to the referent check:

 RewriteEngine On RewriteCond %{HTTP_REFERER} !^http://the-ok-domain.com [NC] RewriteCond %{HTTP_REFERER} !^http://your-domain.com [NC] RewriteRule ^ http://the-website-of-your-choosing.com/ [L,R] 

Then you can include all your pages in the check.

Please note that links can be easily faked, and any htaccess file using mod_rewrite in any of your subdirectories will cancel these rules (unless these htaccess files have the RewriteOptions inheret )

+8
source

Not working for me, I made this small change to redirect traffic from Google:

 RewriteEngine On RewriteCond %{HTTP_REFERER} ^(.*)\.google\.(.*) [NC] RewriteRule ^(.*)$ https://www.my-site.it/$1 [L,R] 
0
source

All Articles