【发布时间】:2023-03-25 12:06:01
【问题描述】:
我正在尝试使用 cookie 保护具有 .htaccess 的目录。重写规则将用户发送到基本目录中的登录 (php)。有用。 当用户登录并获取 cookie 时,脚本会将他重定向到 .htaccess 所在的目录,我必须在其中制定其他重写规则。问题是 .htaccess 无法识别 cookie 并循环返回登录,而是识别它并重定向到目录。 我的 apache 是 > 2.4 with php7.0
在我的 .htaccess 中,我有:
<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>
我用谷歌搜索过,我发现使用 apache >2.4 我可以使用 If-Else,我尝试过使用它,但我不是该语法的专家,我得到一个内部服务器错误,错误为“。 htaccess: 无法解析条件子句:语法错误,日志中出现意外的 T_OP_NOT"。
这是我的 .htaccess 代码:
<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>
有人可以帮助我吗? 万斯感谢
【问题讨论】:
标签: php apache .htaccess mod-rewrite