PDA

View Full Version : .htaccess functionality help needed


sandy
4-12-02, 05:30 PM
I have read all fo the information posted in the forum regarding creating an .htaccess file, and, how to also prevent leeching images. I have followed the instruction, especially the help from MannINC, and other on-line sites. However, whatever I've done, doesn't seem to work. Perhaps I don't understand what I am actually trying to accomplish when I limit leeching files. From what I read, I assumed that if someone entered my site in their own html, that the .htaccess file I load would prevent them from getting to and displaying my images. I put the .htaccess filr in the htdocs directory, where I store all of my images, and after that didn't work, I put the file in the root directory as well. Still, I can get to the images from another website.

This is what is in my file. Is it correct? Do I need to add anyhting else? Am I putting it in the right directory? Am I understanding what I think is supposed to happen when it does work correctly?


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

Thanks for any help!

Sandy

sandy
4-13-02, 03:50 PM
follow-up ..

I found the following code for .htaccess, and, it does stop linking to my images from other sites, but, I now get 500 server errors. Since none of the other codes seem to work for me, can someone please provide a recommendation to what I find works, but also cuts off my site as well:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://sandy-travels.com/.*$ [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG)$

Thanks for any advice.

Sandy

ffejy
4-13-02, 04:14 PM
When exactly do you get 500 errors?

And, from MannInc's support site:
RewriteCond %{HTTP_REFERER} !^http://yoursite.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com/ [NC]
RewriteRule [^/]+.(gif|jpg)$ - [F] # No access to images

Try that... I have never tried to do this before, but that should work.

Jeff

MannInc
4-15-02, 01:00 AM
That code actually will work, as I tested it rigiduously prior to posting it on the site.

Thanks Jeff for posting it here.

Hpe this helps!

sandy
4-15-02, 10:07 AM
Mike / Jeff,

Thanks for posting.

I do have Mike's code, and I have it located at the root directory. However, it didn't appear to do what I "thought" it was supposed to do, that is, not allow other sites to link to my site, simply using my site URL in their webpage. If that isn't the intent of the .htaccess, to limit that, then perhaps I don't understand what the script is supposed to do.

The other script that I listed above, when a test site I have, using geocities, tries to access my images from the sandy-travels.com site on Powweb, the images are not displayed, since they can't be found. However, whenever I go to my own site, and any of my images, I get the 500 internal server error, or, I too can not view my images.

So, any comments in my understanding will be most appreciated.

Regards,

Sandy

ffejy
4-15-02, 10:44 AM
Mike's code is meant to keep other sites from using your images, i.e. they put an img tag that says <img src="http://yourdomain.com/your/picture.jpg">
That code will make it so your picture is not displayed on their site.

I'm not exactly sure what the code you posted before is supposed to do, but if you are trying to keep other sites from putting links to your site, i.e. <a href="http://yourdomain.com"> I do not know how to do that... perhaps someone more familiar with Apache can help you.

If you're trying to stop other sites from linking to your images, i.e. <a href="http://yourdomain.com/your/image.jpg"> and i'm not sure why you would want to, then I think there is a way to do that in htacces, but I do not know.

If you could explain exactly what you are trying to do, I think someone familiar with htaccess and rewrites should be able to help you.

Jeff

sandy
4-15-02, 10:49 AM
Jeff,

>Mike's code is meant to keep other sites from using your images, i.e. they put an img tag that says <img src="http://yourdomain.com/your/picture.jpg">
That code will make it so your picture is not displayed on their site. <

This is what I am trying tp prevent. Other sites simply using the code above on their site, linking to mine.

Specifically, I have the .htaccess file in my root directory. OI have also tried placing it in my htdocs directory (where all of my images are stored). It doesn't seem to matter.

I have a test site: http://www.geocities.com/scperle/test.html
In this html, I have the following :

<IMG SRC="http://www.sandy-travels.com/140.JPG">
<IMG SRC="http://www.sandy-travels.com/141.JPG">

The pictures do display. If I am doing this correctly, and the .htaccess file is in the right place, should the pictures NOT be displayed on the geocities site?

I hope this clarifies what I am trying to do.

Thanks for your help.

Sandy

ffejy
4-15-02, 10:55 AM
Mike's code is supposed to do exactly what you are looking for. Do you have it in the .htaccess file? If you do and it is still not working, try posting it here and perhaps we can find a problem with it.

Jeff

sandy
4-15-02, 10:57 AM
Jeff,

This is all that is in my .htaccess file:

RewriteCond %{HTTP_REFERER} !^http://sandy-travels.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.sandy-travels.com/.*$ [NC]
RewriteRule [^/]+.(gif|jpg)$ - [F] # No access to images

Any suggestions?

Thanks,

Sandy

ffejy
4-15-02, 10:59 AM
You have an extra .*$ at the end of each address... so it should look like this:

RewriteCond %{HTTP_REFERER} !^http://sandy-travels.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.sandy-travels.com/ [NC]
RewriteRule [^/]+.(gif|jpg)$ - [F] # No access to images

besides that everything looks fine... hope this fixes it!

Jeff

sandy
4-15-02, 11:00 AM
I've also tried the basic script that Milke provided:

RewriteCond %{HTTP_REFERER} !^http://sandy-travels.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.sandy-travels.com/ [NC]
RewriteRule [^/]+.(gif|jpg)$ - [F] # No access to images

This is NOW in the file, and that doesn't seem to do the trick either.

Sandy

ffejy
4-15-02, 11:03 AM
Well..... I'm at a loss, maybe Mike can help you with that, it looks fine to me.

Jeff

sandy
4-15-02, 11:06 AM
Thanks Jeff,

I've placed this file in root directory, and then in the htdpcs directory. It didn't seem to work in either location. Right now it resides at the root directory.

Regards,

Sandy

MannInc
4-15-02, 11:21 AM
You need to place that code in a .htacess file under the htdocs folder. If you have other items, such as subdomain rewrite commands, this item wil need to go below them.

Placing the file in the "root" directory, outside of the htdocs will not work at all. It needs to be in htdocs.

Hope this helps!

sandy
4-15-02, 11:58 AM
Mike,

I now have the .htaccess file in the htdocs directory. This still doesn't seem to fix my problem.

This is the .htaccess file:

RewriteCond %{HTTP_REFERER} !^http://sandy-travels.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.sandy-travels.com/ [NC]
RewriteRule [^/]+.(gif|jpg)$ - [F] # No access to images

If you go to this URL, you will note that the pictures are loaded and displayed.

Anything esle that I need to consider?

Thanks,

Sandy

sandy
4-15-02, 12:03 PM
Well, I think I see what is happening.

I changed one of the links to a jpg that was ONLY displayed on my MAIN INDEX.HTML file, and it was not displayed. The other jpg is in a different HTML file, but, the .jpg is stored in the htdocs file.

It seems that the script only applies to the INDEX.HTML file, and not all of the other html files. So, is there a way to make this work for ALL of my html files that are in the htdocs, or, do I need to create the .htaccess file for ALL of my various html files??

I hope not!

Thanks,

Sandy

MannInc
4-15-02, 01:24 PM
Where's the page that where the image is being leeched?

I've set my .htaccess file (using the code from the tutorial) and have been successful at stopping leechers. Try this sample page to see:

http://pwsupport.manninc.com/test.html

Now if you're using subdomains, you'll need to add a .htaccess with the following code:

RewriteCond %{HTTP_REFERER} !^http://sub.yoursite.com/ [NC]
RewriteRule [^/]+.(gif|jpg)$ - [F] # No access to images

The modification for this have been made to the tutorial.

Hope this helps!

sandy
4-15-02, 01:32 PM
Hi Mike,

I now have the anti-l;eeching working on all of my 30 pictures pages. I ended up writing the script for each and every page, 2 times, one including the www in front of the file and the other without the www (have 60 lines in the .htaccess file).

All of my images are stored in the htdocs directory.

What I had originally tested was the following line in the test URL:

CASE 1:
http://www.geocities.com/scperle/test.html
<IMG SRC="http://www.sandy-travels.com/141.JPG">
The image shows

CASE 2
<IMG SRC="http://www.sandy-travels.com/japan.html141.JPG">
The image deoes NOT show

So, if I list each and every html file, the script works.

Now my problem .. since the images are all in htdocs, all one needs to do is access thgem from my index.html and enter a jpg file. such as CASE 1:
<IMG SRC="http://www.sandy-travels.com/141.JPG">Is there a way to protect the images that simply reside in the htdocs directory?

If you look at the test URL, you will see what I mean.
http://www.geocities.com/scperle/test.html

Thanks for all of your help and patience.

Sandy

MannInc
4-15-02, 01:37 PM
The coding is looking for gif and jpg files (small case). Try changing your images to .jpg instead of .JPG and see if that helps any.

I've seen the test page and see why the two pictures that don't load, don't load. You have them as:

<IMG SRC="http://www.sandy-travels.com/picture.html/smn.jpg">

This makes picture.html as a directory, not a page. Try my test page and you'll see that the image doesn't load.

Hope this helps!

sandy
4-15-02, 01:51 PM
OK Mike,

You will note that I have 3 pictures in my test URL.. all with lowercase jpg, and, they all display in the test file.

I'm about to throw in the towel..
http://www.geocities.com/scperle/test.html

Still hoping for a miracle :)

Sandy

MannInc
4-15-02, 01:56 PM
Is the anti-leeching code the only thing in the .htaccess file? Please let me see the entire content of your .htaccess file.

sandy
4-15-02, 01:58 PM
Mike,

This is all I have in the .htaccess file, and, I do have it in htdocs:

RewriteCond %{HTTP_REFERER} !^http://sandy-travels.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.sandy-travels.com/ [NC]
RewriteRule [^/]+.(gif|jpg)$ - [F] # No access to images

MannInc
4-15-02, 02:04 PM
The only thing I can think of at this point is to make sure the file is in fact .htaccess and not something like .htaccess.txt.

Other than that, I'd actually have to have access to your site to check to see what the problem is.

Sorry if I cannot be of more help.

sandy
4-15-02, 02:13 PM
Mike,,

It is just .htaccess

Thanks...