htaccess 无法与 Kohana 3.1.x 一起正常工作
我需要能够访问 /admin_dir 下的所有内容,而不会受到 Kohana 框架的干扰,因为 admin_dir 根本不使用该框架。
首先,这是我的 .htaccess 文件:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
#Allow the admin page to be accessed
RewriteRule ^/?admin_dir(.*) admin_dir$1 [L]
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
这是 Kohana 附带的 .htaccess 文件,减去了 admin_dir 规则的添加。但是,无论我做什么,我都无法访问 admin_dir。我收到 Kohana 异常,表示如果我尝试访问 /admin_dir/index.php,则无法找到匹配的路由,或者如果我尝试访问 /admin_dir,则无法找到 URL。
我似乎能够访问 admin_dir 的唯一方法是注释掉 .htaccess 的最后一行。 admin_dir 不是 Kohana 框架的一部分,所以我只想一起绕过它。我在 SO 上找到了类似的帖子,但没有适合我的情况。
编辑: 我在 admin_dir/ 中有一个 .htaccess 文件用于密码保护。内容如下:
AuthType Basic
AuthName "Admin Page"
AuthUserFile "/home/mysite/.htpasswds/public_html/beta/admin_dir/passwd"
require valid-user
预先感谢您的帮助,这已经是我的眼中钉了太久了!
布莱恩
I need to be able to access everything under /admin_dir without the Kohana framework interfering, since the admin_dir doesn't use the framework at all.
First off, here's my .htaccess file:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
#Allow the admin page to be accessed
RewriteRule ^/?admin_dir(.*) admin_dir$1 [L]
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
This is the .htaccess file that comes with Kohana, minus the addition of the admin_dir rule. However, no matter what I do I can't access the admin_dir. I get a Kohana exception saying that it couldn't find a route to match if I try to access /admin_dir/index.php, or that the URL couldn't be found if I try to access /admin_dir.
The ONLY way I seem to be able to access the admin_dir is by commenting out the very last line of .htaccess. The admin_dir isn't part of the Kohana framework, so I just want to bypass it all together. I've found similar posts on SO about this, but nothing that works for my situation.
Edit:
I do have an .htaccess file in the admin_dir/ for password protection. The contents are below:
AuthType Basic
AuthName "Admin Page"
AuthUserFile "/home/mysite/.htpasswds/public_html/beta/admin_dir/passwd"
require valid-user
Thanks in advance for your help, this has been a thorn in my side for way too long!
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,我的 admin_dir 目录中有 .htaccess 是导致我的问题的原因。我不知道为什么或如何,但在对根 .htaccess 文件进行小更改并删除密码保护后,现在一切正常......除了没有密码保护之外。 :( 我想我只需要为它编写一个愚蠢的小身份验证东西。
这是我们对根 .htaccess 文件所做的修改:
谢谢大家的帮助!
布莱恩
So apparently having the .htaccess in my admin_dir directory is what was causing my problem. I don't know why or how, but after making a small change to the root .htaccess file and removing the password protection, it's all working now... with the exception of no password protection. :( I guess for that I'll just need to write a dumb little authentication thingy for it.
Here's the modification we made to the root .htaccess file:
Thank you all for your help!
Brian
评论
RewriteRule ^/?admin_dir(.*) admin_dir$1 [L]
当您尝试访问 http 时, 是否可以解决您的问题://domain.com/admin_dir/index.php ?
Does commenting
RewriteRule ^/?admin_dir(.*) admin_dir$1 [L]
solve your problem when you try to access http://domain.com/admin_dir/index.php ?
下面的规则将告诉 Apache 不要对以
admin_dir
开头的 URL 进行任何 URL 重写如果它仍然不起作用(在我的测试盒上它确实工作正常),请尝试删除前导
^
- 它不太准确(因为它也会被some_admin_dir
触发),但只要admin_dir
在整个网站中是唯一的(没有其他 URL)有那个文字)那么应该没问题。更新:
您可以尝试将其放入
/admin_dir
中的 .htaccess 中——值得一试:The rule below will tell Apache to not to do any URL rewriting for URLs that start with
admin_dir
If it still does not work (it does work fine here on my test box), try removing leading
^
-- it is less accurate (as it will also be triggered forsome_admin_dir
) but as long asadmin_dir
is a unique across whole website (no other URLs have that text) then it should be fine.UPDATE:
You may try putting this into your .htaccess from
/admin_dir
-- worth trying it: