/    Sign up×
Community /Pin to ProfileBookmark

problem with .htaccess and anti-hotlinking

hello,

sorry if this forum is unappropiated to post this question and spare my life please, but i just dont understand whats happening with .htaccess in my server, im using the following script in order to prevent the hotlinking of my files

[code]
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^[url]http://mydomain.net/.*[/url]$ [NC]
RewriteCond %{HTTP_REFERER} !^[url]http://mydomain.net[/url]$ [NC]
RewriteCond %{HTTP_REFERER} !^[url]http://otheralloweddomain/file/.*[/url]$ [NC]
RewriteCond %{HTTP_REFERER} !^[url]http://otheralloweddomain.com/file[/url]$ [NC]
RewriteRule .*.(gif|htm)$ [url]http://domaintoredirectattemptsto/[/url] [R,NC]
[/code]

All seems to be in order but it simply doesnt work, actually it does prevent hotlinking but also it prevents my own domain and site from linking my own images, the same with the other referer which is a domain i want to allow the hotlinking.

Any idea about what is wrong with this? i will thank you any help you can provide.

Thanks in advance.

to post a comment
Full-stack Developer

3 Comments(s)

Copy linkTweet thisAlerts:
@FangFeb 15.2005 — Ask your provider if you can do this, some providers do not allow it.
Copy linkTweet thisAlerts:
@nukerauthorFeb 15.2005 — Actually its supposed to allow it, thats why i wonder is not working, can you tell me please if the script is correct?

thanks.
Copy linkTweet thisAlerts:
@philawebFeb 16.2005 — [B]nuker[/B],

The code below works for me.

I guess you're missing the bit in red, which checks for empty referers.

Naturally, you need to change domain.com to the appropriate domain of yours.

RewriteEngine on

[COLOR=red]RewriteCond %{HTTP_REFERER} !^$[/COLOR]

RewriteCond %{HTTP_REFERER} !^[url]http://[/url](www.)?domain.com/.*$ [NC]

RewriteRule .(jpg¦jpeg?¦gif¦png)$ http://www.domain.com/ [R,L]

BTW. Why do you want to prevent hot-linking to a HTM(L) document?
×

Success!

Help @nuker spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...