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.

Matt
  • 21
  • 2

1 Answers1

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".

deceze
  • 139
  • 5
  • 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 04 '14 at 05:45
  • Here's a screen shot of my .htaccess file currently, if that helps.

    http://weatherworks.com/CaptureCode.PNG

    – Matt May 04 '14 at 06:04