2

I've been in web development for several years now (I'm a student web designer), and recently, I've begun to experiment with mod_rewrite for things like URL shortening.

I was wondering, is it possible to block a referrer by domain extension, instead of just by full site, etc.?

So, instead of

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} examplesite\.com [NC]
RewriteRule .* - [F]

could you do

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} \.com [NC]
RewriteRule .* - [F]

without the full domain name?

Thanks. I'm fairly knowledgeable about other web dev / hosting topics, but mod_rewrite is new to me and Google wasn't helping.

1

Sure. The right hand expression of the RewriteCond is simply a regular expression. The correct regular expression for matching anything ending in ".com" is:

\.com$

The $ means "end of string".

2
  • It goes in the root directory's .htacess file, right? I tried the above with your $ addition as a test, and it didn't work. I'm wanting to use it to clean up .ru and other odd referrer domains cluttering my logs. Thanks.
    – Matt
    May 4 '14 at 5:45
  • Here's a screen shot of my .htaccess file currently, if that helps. weatherworks.com/CaptureCode.PNG
    – Matt
    May 4 '14 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.