Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

People are able to embed my forum's attachments (vbulletin). I tried to create an htaccess rule for the hotlinking, but it did not work.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com.*$ [NC]
RewriteRule attachmentid=\d+(\&d=\d*)?|\.([Gg][Ii][Ff]|[Jj][Pp][Gg])$ http://mydomain.com/antihotlink.jpeg [R]

Is it not possible to check for numbers in regular expressions in htaccess files?

share|improve this question

migrated from serverfault.com Sep 21 '11 at 6:17

This question came from our site for system and network administrators.

Please provide an example of attachment URL that you are trying to work with. – LazyOne Sep 21 '11 at 8:53
Are you sure your pattern isn't just wrong? You're not telling us what you're trying to match, so it's not really possible to answer the question. – Su' Sep 21 '11 at 8:56
I want to match an url like this: mydomain.com/forum/attachments.php?attachmentid=123456 with an optional "&d=123456" at the end... – reggie Sep 23 '11 at 16:53

You have to use RewriteCond %{QUERY_STRING} to match against the query string -- rewriterule matches only against the path component of the URL.

That's why your rule is a no-op.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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