-1

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 Answers1

0

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>
  • I tried this code. Working on localhost but not on the staging server – Lohit Parihar Sep 21 '22 at 05:12
  • You need to update the file at root of WP or which Server do you use, check whether it is compatible with htaccess file. Or debug more why the environment causing the issue being execute htacess code. –  Sep 21 '22 at 07:37
  • the site hosted on siteground and they say issue not on there end. – Lohit Parihar Sep 21 '22 at 11:29
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 26 '22 at 00:42