Prevent hotlinking PDF files with certain string in it with .htaccess

I want to prevent hotlinking of pdf files when a user is not logged in (with WordPress) and which begin with “restricted_”.

Currently I have the following .htaccess lines:

Read More
#RewriteEngine On
#RewriteCond %{HTTP_REFERER} !^(.*).oegn.at/ [NC]
#RewriteCond %{REQUEST_URI} !hotlink.(pdf) [NC]
#RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
#RewriteRule .*.(pdf)$ http://www.oegn.at/ [NC]

Right now this prevents of hotlinking every .pdf file. I don’t how I can achieve my goal.

Related posts

1 comment

  1. To check the file, you can do next:

    RewriteCond %{REQUEST_URI} ^/restricted_(.*).pdf
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(.*)$ /current_file?=restricted_%1.pdf [R,L]
    

    Now just replace my rewriteRule with what you want.

    If you have any questions, let me know.

Comments are closed.