I want to know how to prevent hotlinking to resources on my site without hard coding the domain name.
I need this since the software will be used for multiple domains, and may be used as an installation. It would not be feasible to instruct every user to make changes in the htaccess file to enter their current domain.
I have come across a lot of code similar to this. but here as you can see you have to enter the domain name.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !www.example.com [NC]
RewriteRule \.(gif|jpg|png)$ - [F,NC]
I have also come across the below snippet from this apache page, which seems to solve the problem. But for some reason cant get it to work.
RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
RewriteRule ^/images - [F]
Note: i have set up a local domain name to perform the tests. so i access my site as mysite.local instead of localhost/mysite
Is there a way i can prevent hotlinking without hard-coding the domain name in the htaccess ?