由于我对mod_rewrite缺乏了解以及对该项目的时间限制,所以一直在寻找2天并且无法得到正确的解决方案,因此希望有人可以提供帮助.
目的
如果客户端没有正确的cookie,则重写对根index.php的所有请求.如果客户端具有正确的cookie,则允许他们按照自己的意愿进行浏览.
问题
我子目录中的htaccess优先于我的root htaccess,因此www.mydomain.com/subdir/index.php等请求不会被重定向.
我的根.htaccess
Options FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} !^.*pass.*$
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^(.*)$ http://www.mydomain.com/index.php?url=$0 [NC]
Run Code Online (Sandbox Code Playgroud)
我的子公司htaccess
RewriteEngine On
RewriteBase /
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Run Code Online (Sandbox Code Playgroud)
附加信息
理想情况下,我正在尝试创建一个受密码保护的区域,因此所有请求都会路由到index.php,在这里可以输入密码,并在验证时创建cookie,允许自由浏览内容和子目录.所以,如果有更好的方法来实现这一点,那么请让我知道,因为我需要自定义登录,错误和启动页面,所以我没有去.htpasswd.
此外,subdir .htaccess是一个ExpressionEngine URL处理程序.
谢谢.