[ad_1]
I know there are articles on the subject but I can’t get the htaccess rule to work. Well, it works but only if the PDF is in a specific folder.
Here’s what I’m trying to do :
If someone doesn’t have the wordpress_logged_in cookie and they try to view a pdf or ppt, then we redirect them to the login page.
Here is my current htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteCond %{HTTP_COOKIE} !wordpress_logged_in [NC]
RewriteRule ^wp-content/uploads/.+?\.(pdf|ppt)$ wp-login.php?redirect_to=/ [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
It dont works.
The next one works if i’m trying to access /uploads/2022/05/blabla.pdf but not /wp-content/uploads/2022/05/blabla.pdf
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteCond %{HTTP_COOKIE} !wordpress_logged_in [NC]
RewriteRule (^|/)uploads/.+?\.(pdf|ppt)$ wp-login.php?redirect_to=/ [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Why If I add “^wp-content/” it dont works at all?
[ad_2]