admin管理员组

文章数量:1384278

I would like to redirect all of the following urls if a WordPress user is not logged in (or WordPress cookie is set) using .htaccess.

  1. .html

  2. .html#page=1

  3. .html#page=2 etc etc

This is what I have tried :

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_COOKIE} !.*wordpress_logged_in.*$ [NC]
    RewriteCond %{REQUEST_URI} ^(.*?/?)wp-content/uploads/sample_pdf/(.+) [NC]
    RewriteRule . http://%{HTTP_HOST}%1/wp-login.php?redirect_to=%{REQUEST_URI} [L,QSA]
</IfModule>

and

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_COOKIE} !.*wordpress_logged_in.*$ [NC]
    RewriteCond %{REQUEST_URI} ^(.*?/?)wp-content/uploads/sample_pdf/.* [NC]
    RewriteRule . http://%{HTTP_HOST}%1/wp-login.php?redirect_to=%{REQUEST_URI} [L,QSA]
</IfModule>

Both of these options redirect the first URL :

But not the others.

Can you please let me know where my regex is going wrong & why it's not grabbing everything in the /sample_pdf directory.

本文标签: htaccessRedirect files in uploads directory if WordPress user not logged in