Htaccess Question

by 3 replies
4
Does anyone know how to write htaccess to deny everyone and allow only certain referrer? I've tried many things and nothing works
#programming #apache #htaccess #question
  • 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.
    • [1] reply

    • 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!
      • [1] reply

Next Topics on Trending Feed