【发布时间】:2012-07-02 16:18:01
【问题描述】:
===== 澄清 =====
请注意这一点,与此类似的帖子有数百个答案,但人们只涉及问题的一部分,而不是我在这里问的真正问题。
=====
我正在使用 Kohana 3.2,我想从 url 中完全删除 index.php。比如我想访问控制器foo,action bar。
通常,正确设置引导程序和 htaccess,我可以这样访问:
www.domain.com/foo/bar.
但我也可以这样访问:
www.domain.com/index.php/foo/bar
我希望只允许用户像第一种方式那样访问,而不像第二种方式那样访问。
我在 bootstrap.php 中有这个部分:
Kohana::init(array(
'base_url' => '/',
'index_file' => '',
));
我尝试取消 index_file 行,将其值更改为 FALSE,我仍然能够以两种方式访问 foo/bar。
我认为解决方案是修改 htaccess,但我尝试了一些更改,但它没有按我的意愿工作。我正在使用 kohana 附带的原始 htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /knisu/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# 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]
任何帮助将不胜感激:)
编辑: 我在另一篇文章中找到了一个可以使它起作用的答案:
# Redirect from:
# http://localhost/index.php/welcome
# to
# http://localhost/welcome
#
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^index\.php/?(.*)?$ $1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?/$1 [L]
问题是,作者说:“这可行,但问题在于存在的文件和目录,他必须放置图像、css、js 等的完整路径......我稍后会修复”
这可能有助于找到最终解决方案吗?
【问题讨论】:
标签: kohana