1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with simple htaccess script

Discussion in 'General Scripting Chat' started by conway943, Oct 11, 2012.

  1. conway943

    conway943 Newbie

    Joined:
    Sep 27, 2012
    Messages:
    13
    Likes Received:
    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: Oct 11, 2012
  2. cgimaster

    cgimaster Power Member

    Joined:
    Jun 30, 2012
    Messages:
    526
    Likes Received:
    311
    Gender:
    Male
    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
     
    • Thanks Thanks x 1
  3. conway943

    conway943 Newbie

    Joined:
    Sep 27, 2012
    Messages:
    13
    Likes Received:
    0
    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: Oct 11, 2012
  4. cgimaster

    cgimaster Power Member

    Joined:
    Jun 30, 2012
    Messages:
    526
    Likes Received:
    311
    Gender:
    Male
    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.