How to check if Drupal user is logged in via htaccess? Is there a specific cookie Drupal uses to determine if a user is logged in or anonymous? 

I need to check the cookie, and create a rewrite condition based on whether or not the user is logged in.

In the end, I would like something like this:

RewriteCond %{HTTP_COOKIE} !drupaluser=1 [NC]
RewriteRule ^(.*)$ /$1?no-cookies-for-you=%1 [R,QSA,L]


Thanks.
Drupal does store the session value in the cookie variable after the user is logged in. However, the name of this cookie is not fixed. It is basically a string that comes from the value returned by PHP function session_name; and starts with SESS. It would be hard to find and I would not recommend using regex, as I personally don't like it much.

If you really want to implement a solution with the cookie, I would suggest the following:


Implement hook_user_login() in a custom module:

function MODULE_user_login() {
  // set a new cookie here, with static name and value.
}

Implement hook_user_logout() and delete the cookie by setting an expiry date of past.


You can now use this cookie in your .htaccess!