1

In my .htaccess, it return 403 if user accesses image directly, but allows them to be displayed on site. I've read (htaccess) How to prevent a file from DIRECT URL ACCESS? in order to achieve this.

This is my .htaccess

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myapp.dev/ [NC]
RewriteRule \.(gif|jpg|JPG|jpeg|png)$ - [F]
Options -Indexes

What I want to do next is that if the url contains "pdf" (e.g. myapp.dev/pdf/stuff.png) I will not use or skip this code

RewriteRule \.(gif|jpg|JPG|jpeg|png)$ - [F]

Maybe I could modify the RewriteCond or the RewriteRule and add a condition...

Any ideas/alternatives will be of help!

Community
  • 1
  • 1
yowza
  • 260
  • 2
  • 14

1 Answers1

0

To forbid .pdf requests , you can use :

RewriteRule \.pdf$ - [F,NC] 

Edit :

Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myapp.dev/ [NC]
RewriteRule ((?!pdf).+)\.(gif|jpg|JPG|jpeg|png)$ - [F]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115