Seeing as they are images, I would either serve up an image (with some text on it, like “hotlinking not allowed”), or change [NC] in the Rule to [NC,F] to just forbid access (so it returns a 403 access denied).
Your English translation of the code is correct btw :tup:
Mittineague and ScallioXTX - The best two SitePoint gurus,
Thanks for the help.
So you mean change
RewriteRule \.(gif|jpe?g)$ blank.txt [NC]
to
RewriteRule \.(gif|jpe?g)$ blank.txt [NC,F]
so the hotlinking site gets a 403 error, right?
The one thing I don’t understand is where the differentiation in the code is.
If you boil the meaning of these lines of code to
RewriteCond %{HTTP_REFERER} !^$ NO Accsess To image
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com/ [NC] OK
RewriteCond %{HTTP_REFERER} !^http://www.trusted\.com/ [NC] OK
Then what is the code in these lines that says no action on this, take action on this other?
Those three lines are all conditions. All three conditions (refererer [sic] must not be empty, and must not be the domain of your site, and must not be the domain of you trust). If and only if all conditions match will the rule be evaluated.
(Internally it’s the other way around, the Rule is validated first, and only if it matches will the Conds be validated, but that’s not really relevant here ;))
Felgall,
So RewriteCond %{HTTP_REFERER} !^$ is code for blank referers (due to a privacy setting visitors use in their browsers) has what purpose in my .htaccess? It prevents or enables what?
Does it allow visitors using a privacy setting to see the images (or whatever files) on my site and the reason it would be put in my htaccess is because a blank user agents don’t look anything like a regular useragents - regular user agents of people visiting a site are identified as having a certain format, and websites visiting my site to use an image (or use something else) have a different format. A blank useragent has no format, so with the code being discussed, if I didn’t have RewriteCond %{HTTP_REFERER} !^$ then people using a privacy settig wouldn’t be able to see the images on my site.
When you get a chance can you give me an example of a user agent from a visitor to my site and an example of a user agent to my site from another website.
It’s just a header in the HTTP request that indicates the URL the user came from. So if I go from page A to page B, the browsers sends the URL of page A as the referer for page B.
Also, when you are on page B and that page has images on it, the browser will send the URL of page B as the referer for those images.
Basically the referer answers the question “why is the visitor downloading this file?”
Does that make sense?
The User Agent and Referer are not connected in any way btw. Okay, in certain User Agents you can disable or fake the referer, but that’s the extent of it.
Scallio,
I thought the user agent was that bit of code in a browser you find by typing in about:blank (or something like that). I thought referrrer was the same thing.
You say it’s just a header in the HTTP request. Doesn’t a request from a human visitor on a browser to my website look different than a request from a website contacting my website (e.g. hot linking).
I think we have different definitions of hot linking.
My definition of hot linking is: people putting an image on their own website by putting an <img> on there with the URL of my website in there.
So if my website is example.com and somewebsite.com has <img src="http://www.example.com/image.gif" alt="Some image" /> on their website then somewebsite.com is hotlinking from me.
It’s got nothing to do with User Agents.
It sounds like what you are referring to is scraping, which is something else entirely.
No you can’t remove it, because a RewriteRule always needs to have at least a regular expression and a new URL. You can use a a dash though, which means “don’t rewrite at all”.
So this appears to be my final
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.google\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yahoo\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.bing\.com/ [NC]
RewriteRule \.(gif|jpg|css|png)$ - [NC,F]
Which allows visitors using some blanking privacy setting, allows images to show up on my site and google, yahoo, bing, and every one else gets F-ed (Four O three-ed).
Should that “css” be in there, I saw it somewhere else? What would somone gain by linking to my css?