我有一个困扰我一天多的问题,我真的不知道该去哪里找。
我有一个网站设置了一个名为cms的子目录,它使用的是基本的htpasswd登录。所有对主站点的请求都使用htaccess重定向到index.php,除了对cms-文件夹、图像等的请求。
这将导致www_root中的以下htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.domain\.nl [NC]
RewriteRule ^(.*)$ https://www.domain.nl/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/cms
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css|\.js|favicon\.ico|\.svg|\.pdf|\.ino)$ [NC]
RewriteCond %{REQUEST_URI} !^/robots.txt$ [NC]
RewriteCond %{REQUEST_URI} !^/BingSiteAuth.xml$ [NC]
RewriteCond %{REQUEST_URI} !^/apple-app-site-association$ [NC]
RewriteRule (.*) framework/index.php [L]在cms-文件夹中有一个单独的htaccess,只包含身份验证内容:
AuthName "CMS"
AuthUserFile /path/to/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
require valid-user问题是,当我请求CMS /index.php时,请求被重定向到framework/index.php,而不是cms/index.php,就像RewriteCond %{REQUEST_URI} !^/cms不在主htaccess中一样,除非我删除了cms/.htaccess,在这种情况下,一切都正常,我能够到达(现在没有保护)CMS。
该站点使用Apache2.4.16和PHP5.6在Redhat Linux服务器上运行。
发布于 2016-03-21 17:48:18
试着打开调试日志以查看发生了什么:
RewriteLog "/tmp/debug.log"
RewriteLogLevel 6当您逐步浏览站点上的URL时,日志将向您展示哪些规则是匹配的,以及原因。
例如,当我设置它并观看/tmp/debug.log时,我可以看到这个请求(/somedirectory)被重写了:
(4) RewriteCond: input='/somedirectory' pattern='!^/cms' => matched
(2) rewrite '/somedirectory' -> 'framework/index.php'
(2) local path result: framework/index.php这个请求(/cms)没有重写:
(2) init rewrite engine with requested uri /cms/index.php
(3) applying pattern '(.*)' to uri '/cms/index.php'
(4) RewriteCond: input='/cms/index.php' pattern='!^/cms' => not-matched
(1) pass through /cms/index.phphttps://stackoverflow.com/questions/36135433
复制相似问题