Score:1

Add a subdomain as an exception in hotlinking

sc flag

I used this code in my .htaccess file and it is working great to prevent hotlinking:

RewriteEngine On
RewriteCond %{HTTP_HOST}@@%{HTTP_REFERER} !^([^@]*)@@https?://\1/.*
RewriteRule \.(gif|jpg|jpeg|png|tif|pdf|wav|wmv|wma|avi|mov|mp4|m4v|mp3|zip?)$ - [F]

Now I want to allow one of my subdomains (cdn.example.com) to access my files using a GET request.

It is not possible to add http_reffer to my GET request! I should only handle it with .htaccess.

How should I add my subdomain as an exception in this code?

kz flag
"It is not possible to add http_reffer to my GET request!" - What do you mean by this exactly? If the `Referer` header is not being sent as part of the request (for some reason) then you cannot allow this specific hostname, you would need to allow for an _empty_ `Referer` header, which will mean _direct_ requests will also be permitted.
kz flag
Cross-site dupe on StackOverflow: https://stackoverflow.com/questions/71369817/add-subdomain-as-exception-in-hotlinking
Score:0
kz flag
RewriteCond %{HTTP_HOST}@@%{HTTP_REFERER} !^([^@]*)@@https?://\1/.*

Use the following condition instead to allow for an optional cdn subdomain:

RewriteCond %{HTTP_HOST}@@%{HTTP_REFERER} !^([^@]*)@@https?://(cdn\.)?\1/

(The trailing .* is not required.)

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.