Forum Moderators: phranque

Message Too Old, No Replies

Quickie - wildcard in domain in .htaccess

         

Nick_Hope

5:31 pm on Jul 16, 2005 (gmt 0)

10+ Year Member



I've been successfully preventing hotlinking of my images with my .htaccess file but enabling Google image search to hotlink. Now I want to enable some more search engines to hotlink to my images. Here is how my .htaccess file is looking:

<Files .htaccess>
deny from all
</Files>
ErrorDocument 401 /error_docs/401.html
ErrorDocument 403 /error_docs/403.html
ErrorDocument 404 /error_docs/404.html
Options +FollowSymlinks +SymlinksIfOwnerMatch
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite1\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite2\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite3\.info [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite4\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://images\.google\. [NC]
RewriteCond %{HTTP_REFERER}!^http://search\.msn\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://*\.search\.yahoo\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://web\.ask\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://search\.lycos\.com [NC]
RewriteCond %{REQUEST_URI}!^/images/hotlink\.gif$
RewriteRule \.(gif¦jpe?g¦wmv¦png¦php)$ /images/hotlink.gif [L]
php_flag register_globals off

My specific question is, have I got the syntax correct for the line that refers to yahoo?

I would like the regular expression wildcard to include [images.search.yahoo.com...] but also country-specific image searches such as [uk.search.yahoo.com...]

I just stuffed an asterix in there but I suspect it's not as simple as that.

Thanks!

jdMorgan

4:44 am on Jul 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need ".*" ahead of .yahoo.com. An unescaped "." means "any character", and "*" is a quantifier, meaning "zero or more of the preceding character or parenthesized grouped characters. In your code, you were saying, "zero or more of the preceding slash," which is not what you wanted.

So, it's


RewriteCond %{HTTP_REFERER} !^http://.*\.search\.yahoo\.com [NC]

I'm not familiar with all of the .cc domains, but be on the lookut for yahoo.co.uk and similar -- Your pattern may need to take those into account. You could use ...yahoo\.co(m¦\.uk), for example. (Replace the broken pipe character "¦" with a solid pipe from your keyboard before use, though; Posting on this board modifies those characters.

See the regular expressions tutorial cited in our forum charter [webmasterworld.com] for an introduction to this powerful pattern-matching tool.

Jim

Nick_Hope

5:25 am on Jul 17, 2005 (gmt 0)

10+ Year Member



Thanks very much for your help Jim. I must admit that as an occasional user I find the regular expressions stuff to be heavy going and tend to make mistakes so a little assistance is greatly appreciated.

I think I'm covered for Yahoo's country variants as they all seem to redirect to [something.yahoo.com...]