homepage Welcome to WebmasterWorld Guest from 54.198.33.96
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod rewrite/hotlinking problem
Images broken for some visitors, not others?
anam32




msg:1522390
 4:48 pm on May 9, 2003 (gmt 0)

I've poked around some threads here but I'm not nearly as proficient as you folks and I didn't catch anything that I thought applied to my particular problem. If the answer is indeed already out there, please forgive me for not getting it ;-)

I have a Linux host running Apache, and in the CPanel is a place to turn on hotlink protection. I did this awhile back and no one reported any problems. A friend went to the site yesterday and said that on the main page all the images were broken. I don't see that they are myself, and what I find odd is that one image has an absolute path (and it's correct), so surely it isn't just because of the relative ones. I asked a few other people and all of them said things looked fine. I have no errors showing in my logs.

This same friend has a site hosted on the same server, and had this problem awhile back with his own site. When I asked the host about it, they said he had rewrites and they removed them. He then had no problems. I just removed my own rewrites and now he sees my site fine. He has viewed from 2 different locations with the same results, so it wasn't just his PC. I am now wondering if others might have been seeing broken images on my site, and why this would happen to some people and not others. Or does he just have REALLY bad karma ;-)

This is essentially the rewrite that I had in the .htaccess in /public_html/, which was automatically generated in the CPanel:

Options +FollowSymLinks

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.subdomain_mydomain.com.mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://subdomain.mydomain.com/.*$ [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ [mydomain.com...] [R,NC]

Is this correct? And why would someone get broken images while on my site (image files are fine and properly linked) yet others do not?

Thanks so much for any help you can give :-)

 

jdMorgan




msg:1522391
 7:35 pm on May 9, 2003 (gmt 0)

anam32,

Welcome to WebmasterWorld [webmasterworld.com]!

One possible problem is that your rewrite does not account for requests with blank referers - a very common occurance. In many cases, users connecting through proxy servers - such as AOL - will have the referer string stripped from their requests.

Another possible problem is that the rewrite rule is redirecting requests for image files to an html file - to your home page. Browsers can't handle that kind of a file-type change.

Here's some code I'd recommend:

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?(subdomain_mydomain\.)?mydomain.com/ [NC]
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ - [F]

This will allow referers from your domains and subdomains, and also allow blank referers. Others will receive a 403-Forbidden response.

Note that you will have to edit this to fix the "¦" characters - they are modified by posting on this forum. Use the solid vertical pipe character from your keyboard to replace them.

HTH,
Jim

anam32




msg:1522392
 8:23 pm on May 9, 2003 (gmt 0)

Hi Jim,

Thanks for the response. I tried your code, making sure I replaced the pipes and put in my domain name where applicable. But it causes my site to come up with a 500 internal server error. I went back and cleared it all off the .htaccess and set the hotlink protection again via Cpanel so I could see their code again. If this is the line for the blank referrers, it does have it in there:

RewriteCond %{HTTP_REFERER}!^$

I just don't know what's going on here...hopefully it's only my friend getting this. When he had this problem with his own site (same server) I didn't see a problem there, the images were fine. I keep thinking it's just him but I don't understand why he would see broken images from 2 different computers and ISP's, but have the problem be fixed when mods are removed. He has DSL at one, and doesn't use AOL anywhere. Any other ideas from anyone would be most appreciated :-)

jdMorgan




msg:1522393
 9:37 pm on May 9, 2003 (gmt 0)

Sorry, forgot to mention that WebmasterWorld eats spaces preceding "!" as well. The code should read:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?(subdomain_mydomain\.)?mydomain.com/ [NC]
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ - [F]

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved