Forum Moderators: phranque

Message Too Old, No Replies

question about .htaccess

I am using .htaccess for hotlinking but i have a lil problem

         

americanchic87

5:46 pm on Nov 23, 2003 (gmt 0)

10+ Year Member



I am using this .htaccess code to stop direct linking to my site because I have so many images. The problem is when I used this and put it in the images on my site which i am using from my server changed to the picture i put in for the direct linkers. I know this is because technically i am direct linking too but how do I change this so that my images work but not any other sites? That is the code i am using.
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?your-domain.com/.*$ [NC]
RewriteRule \.(gif¦jpg)$ http://www.your-domain-linkgraphic.png [R,L]

ErrorDocument 404/your-domain.com/404error.html
ErrorDocument 404 /404error.html
ErrorDocument 403/your-domain.com/403.html
ErrorDocument 403 /403.html

<Limit GET PUT POST>
order allow,deny
allow from all
deny from 000.000.000.000
</Limit>

is the code i am using....Thanks for all your help!

[edited by: jdMorgan at 2:24 am (utc) on Nov. 24, 2003]
[edit reason] De-linked URLs [/edit]

jdMorgan

7:19 pm on Nov 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



americanchic87,

Welcome to WebmasterWorld [webmasterworld.com]!

This is not at all clear:
> The problem is when I used this and put it in the images on my site which i am using from my server changed to the picture i put in for the direct linkers.

Do you have a second hostname that uses images from the host where your .htaccess code above is installed? If so, you'll need an exclusion to allow that host to use the images:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?other-permitted-domain\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your-domain\.com [NC]
RewriteRule \.(gif¦jpg)$ /linkgraphic.png [L]

(Note the other minor 'tweaks' as well.)

Jim

americanchic87

7:49 pm on Nov 23, 2003 (gmt 0)

10+ Year Member



Ok maybe I can word it better. When I use the .htaccess code the images i am using on my pages turn into the picture i put in the htaccess code for the people who direct link so how do i make it to where i am the only one that is allowed to direct link?

jdMorgan

8:15 pm on Nov 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> i am the only one that is allowed to direct link

Defining the word "I" in that sentence is the difficult part here.

I think maybe it means "my home/personal computer." In which case, you probably need to add something to allow your computer's IP address (or your remote hostname) to access your images... Something like:

RewriteCond %{REMOTE_HOST} !^192\.168\.0\.27$

with your machine's IP address plugged in there and escaped as shown. That is only going to work if your computer has a fixed IP address, I.e., it probably won't work with a dial-up account.

This is what you will need to view your images while using FrontPage or some other WYSIWYG editor if you are using canonical, rather than local image URLs, and your local machine is not running server software. That is, if your source code reads:

<IMG SRC="http://www.yourdomain.com/images/imagefile.jpg"> instead of <IMG SRC="/images/imagefile.jpg">. If you use the second form, then your editor will look for images on your local machine, instead of getting them from your server.

To avoid major confusion, remember to flush your browser cache every time before you test an image for hotlinking behaviour... before every page load or page reload. For Internet Explorer, that is the Delete Temporary Internet Files command under Internet Options. Or, you can set the temp files cache size to zero, turning the cache off while you test.

Jim