Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Mod rewrite/hotlinking problem

Images broken for some visitors, not others?

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

10+ Year Member

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 :-)

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member


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.


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

10+ Year Member

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 :-)

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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]


Featured Threads

Hot Threads This Week

Hot Threads This Month