I'm trying to protect with cookie a directory with an .htaccess. The rewrite rule sends the user to the login (php) in the base directory. It works. When the user login and take the cookie, the script redirects him to the directory where there is the .htaccess where I have to make other rewrite rules. The problem is that the .htaccess doesn't recognize the cookie and makes a loop going back to the login that, instead, recognize it and redirects to the directory. My apache is > 2.4 with php7.0
In my .htaccess I have:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_COOKIE} !(utente_xxx) [NC,OR]
RewriteRule ^.*$ http://www.domain.xxx/login.php [R,L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
I've googled and I found that with apache >2.4 I can use If-Else, I've tried to use it but I'm not expert of that syntax and I obtain an Internal Server Error with the error ".htaccess: Cannot parse condition clause: syntax error, unexpected T_OP_NOT" in the logs.
This is my .htaccess code:
<If "%{HTTP_COOKIE} !(utente_xxx)">
RewriteRule ^.*$ http://www.domain.xxx/login.php [R,L]
</If>
<Else>
<If "%{REQUEST_FILENAME} !-f">
RewriteRule . index.php
</If>
</Else>
Can someone help me? Thanks in andvance