Reputation: 35
I got a problem with the following code in my .htaccess
file:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(tv\.)?my-domain\.com:16500 [NC]
RewriteCond %{HTTP_REFERER} !^http://(tv\.)?my-domain\.com:16500.*$ [NC]
RewriteRule \.(gif|jpg|js|txt|mp4|mp3)$ /redirect/error.mp4 [L]
So what this code does, is, it allows that ONLY tv.my-domain.com:16500 can stream the content that is in the folder where the .htaccess
is located.
This all works fine BUT, what do I have to do if I want to add an IP address (together with the already existing rule for the domain) to the list of HTTP referees that are ALLOWED to access the files?
This code does NOT work:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(tv\.)?my-domain\.com:16500 [NC]
RewriteCond %{HTTP_REFERER} !^http://(tv\.)?my-domain\.com:16500.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://?10.0.0.2:16500 [NC]
RewriteCond %{HTTP_REFERER} !^http://?10.0.0.2:16500.*$ [NC]
RewriteRule \.(gif|jpg|js|txt|mp4|mp3)$ /redirect/error.mp4 [L]
So, can someone please tell me what the correct way of doing this would be?
Thank you in advance!
Upvotes: 1
Views: 688
Reputation: 4917
That is because you need to use %{REMOTE_ADDR}
and not %{HTTP_REFERER}
for IP addresses.
So the syntax would be like this:
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
Make sure you clear your cache before testing this of course.
Upvotes: 1