Need help with simple htaccess script

conway943

Newbie
Joined
Sep 27, 2012
Messages
13
Reaction score
0
I need an htaccess script that will allow only user only with a referral from my website to access a page. If there is no referral from my page i want to direct them somewhere else.
 
Last edited:
Not tested but you could try:

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !http://www\.refererfrom\.com/(.*) [NC]
RewriteRule ^.*$ http://www.redirectto.com/ [R=301,L]

! is negation, so if the refer is not that, it should redirect
You can replace the:
Code:
http://www\.refererfrom\.com/(.*)

By a complete url for example:
Code:
http://www\.blackhatworld\.com/blackhat-seo/editpost\.php

Using the
Code:
(.*)
It will match whatever comes after the domain url
 
It works, but how do i add a 302 to the script for verified redirects. I tried through cpanel but i don't think it's agreeing with the htaccess, as the 302 won't work. it simply displays the page normally for verified users.
 
Last edited:
Well that depends if you are following the link on the page or on a new page, if the user opens it on a new page the referer would be lost.

By changing on the previous htaccess 301 to 302 should work but depends on the above to retain the referer or not
Code:
[R=302,L]

It might be possible that you also have something else on the htaccess that is conflicting, if u want you can pm me your htaccess to take a look at it.
 
Back
Top