htaccess rule for restrict not logged in user to access direct pdf link in wordpress

Viewed 31

Htaccess rule for restrict not logged in user(cookie based) to access direct pdf link in Wordpress. I have tried the rules to restrict access on local host it worked partially on it but when applied on the live website rules not seems to work. The code i have tried mentioned below.

RewriteCond %{REQUEST_URI} \.(pdf)$ [NC]
RewriteCond %{HTTP_COOKIE} !^.*cookie_name.*$
RewriteRule . https://%{HTTP_HOST}%1/contact-sales/ [L,QSA]
1 Answers

Hey you can try below snippet

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_URI} ^.*uploads/.*
  RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
  RewriteRule \.(pdf)$ - [F]
</IfModule>
Related