3 replies
Does anyone know how to write htaccess to deny everyone and allow only certain referrer? I've tried many things and nothing works
#apache #htaccess #question
  • Profile picture of the author KathyK
    Code:
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_REFERER} !^http://(www.)?your_domain.com/ [NC]
    RewriteCond %{HTTP_REFERER} !^http://(www.)?gooddomain.com/ [NC]
    RewriteCond %{HTTP_REFERER} !^http://gooddomain.com/ [NC]
    RewriteRule ^.*$ http://yourdomain.com/notallowed.html [R=301,L]
    Your rewrite base is wherever the .htaccess file is...
    I think you'll need to include your own domain or it may not work.

    Untested, but I think it will work. Keep in mind that some people/programs block referer by default (I think Norton does) so you might also need a blank referer. It SHOULD redirect anything not equal to those referrers.

    Method 2
    Have the index be your 'everyone else' page
    Code:
    RewriteBase /
    RewriteCond %{HTTP_REFERER} ^http://(www.)?your_domain.com/ [NC]
    RewriteCond %{HTTP_REFERER} ^http://(www.)?gooddomain.com/ [NC]
    RewriteRule ^.*$ http://yourdomain.com/yourprivatesalespage.html [R=301,L]
    And this one should redirect anything that IS equal to those referrers.
    Signature

    Cheers,
    Kathy

    {{ DiscussionBoard.errors[401549].message }}
    • Profile picture of the author activetrader
      Originally Posted by KathyK View Post

      Code:
      RewriteEngine on
      RewriteBase /
      RewriteCond %{HTTP_REFERER} !^http://(www.)?your_domain.com/ [NC]
      RewriteCond %{HTTP_REFERER} !^http://(www.)?gooddomain.com/ [NC]
      RewriteCond %{HTTP_REFERER} !^http://gooddomain.com/ [NC]
      RewriteRule ^.*$ http://yourdomain.com/notallowed.html [R=301,L]
      Your rewrite base is wherever the .htaccess file is...
      I think you'll need to include your own domain or it may not work.

      Untested, but I think it will work. Keep in mind that some people/programs block referer by default (I think Norton does) so you might also need a blank referer. It SHOULD redirect anything not equal to those referrers.

      Method 2
      Have the index be your 'everyone else' page
      Code:
      RewriteBase /
      RewriteCond %{HTTP_REFERER} ^http://(www.)?your_domain.com/ [NC]
      RewriteCond %{HTTP_REFERER} ^http://(www.)?gooddomain.com/ [NC]
      RewriteRule ^.*$ http://yourdomain.com/yourprivatesalespage.html [R=301,L]
      And this one should redirect anything that IS equal to those referrers.

      Thank you so much. I really like the second idea. The first version looks familiar like I've tried it before, but the second one is an excellent idea. I haven't thought of it before. My IT guy writes some complicated PHP code for me whereas the download page is a temp file authomatically generated after receiving payment confirmation and only works for one IP address and only for two hours, but it was too complicated for me to understand plus I always had to contact him for support.

      With htaccess I can set up my thank you page myself. Thanks again!
      Signature

      Me

      {{ DiscussionBoard.errors[404348].message }}
      • Profile picture of the author CorporatePuppet
        Yeah I've always used that first example. Got it from a google search awhile back.
        {{ DiscussionBoard.errors[404824].message }}

Trending Topics