Solved

Apache mod_rewrite, restrict non-referrers, allowing www

Posted on 2006-06-16
4
684 Views
Last Modified: 2008-02-26
Hello,

I asked this question yesterday, and got a great solution.
http://www.experts-exchange.com/Web/Web_Servers/Apache/Q_21887572.html

My question is:  In the following .htaccess file (that uses mod_rewrite), how
do I allow referrers with the "www" and without it?


RewriteEngine On
# detect the referrer, match on all other domains
RewriteCond %{HTTP_REFERER} !(http://domain\.com(.*)?$)
# This rule fills all requests with the content of the /denied.html file
RewriteRule ^.*$ /denied.html [L]


Thank you,

Eric
0
Comment
Question by:instantprofits
  • 4
4 Comments
 
LVL 30

Expert Comment

by:callrs
ID: 16926261
Replace line 3 with:
RewriteCond %{HTTP_REFERER} !(.*\.domain\.com(.*)?$)
0
 
LVL 30

Expert Comment

by:callrs
ID: 16926266
No, Nvm. That will catch www.domain.com but not domain.com
brb
0
 
LVL 30

Expert Comment

by:callrs
ID: 16926311
RewriteCond %{HTTP_REFERER} !((\w+):\/\/(([^/:]+\.)|)domain\.com(:\d*)?([^# ]*))

This will allow http://www.domain.com but exclude e.g. http://thedomain.com

0
 
LVL 30

Accepted Solution

by:
callrs earned 500 total points
ID: 16926328
The above will allow http ftp://  as well as http://, etc.
But to make it ONLY for http:
RewriteCond %{HTTP_REFERER} !((http):\/\/(([^/:]+\.)|)domain\.com(:\d*)?([^# ]*))
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question