Forum Moderators: phranque

Message Too Old, No Replies

Allow hotlinking in htaccess

         

Bas_J

8:22 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



Hi all,

This is my first post here, thanks in advance for helping me!

This is my current .htaccess file
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?my-site.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ - [F]

Does anybody know how to rewrite this so that it will allow one of my other sites (for example my-site2.com) to hotlink images and still not allowing it for all other sites? Thanks!

bcolflesh

8:24 pm on Feb 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<edit> Welcome to WW </edit>

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?my-other-site.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?my-site.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ - [F]

Bas_J

8:56 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



thanks for your reply! I have rewritten and uploaded the new htaccess file but the images I hotlinked from "my site" still don't show on "my other site"
I don't get it? Is there another way to do this?

bcolflesh

8:59 pm on Feb 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check your log files - are there 403 error hits from "my-other-site" to the images in question?

jdMorgan

9:17 pm on Feb 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be sure to flush your browser cache before *each* test.

Jim

Bas_J

9:25 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



yes they do show, what does it mean if they didn't?

jdMorgan

9:27 pm on Feb 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd like to suggest the following changes to the code in the interest of others who may see the thread later. The code posted above should work fine in almost all cases, but we have problems here with the forum software deleting spaces between "}" and "!". Also, the literal periods in patterns need to be escaped by preceding them with a backslash in the interest of precision, referrers can "legally" contain a port number (e.g. "example.com:80/"), and ".*$" at the end of a pattern can be safely omitted in the interest of efficiency without changing the meaning of the pattern whatsoever.

RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?my-other-site\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?my-site\.com [NC]
RewriteRule \.(gif¦jpg)$ - [F]

In addition, be sure to change all broken pipe "¦" characters to solid pipe characters before use.

Jim

[edited by: jdMorgan at 9:29 pm (utc) on Feb. 27, 2004]

bcolflesh

9:28 pm on Feb 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Flush your cache as previously suggested - if you are still getting 403s, does the log line show the REFERRER info as being the same as what you put into .htaccess?

<edit> thanks for code correction jdMorgan! </edit>

Bas_J

9:42 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



The last code jdMorgan provided works like a clock. Bcolflesh & jdMorgan thanks a lot for your help!