【发布时间】:2013-10-18 08:36:32
【问题描述】:
在我的测试应用程序中,我试图从 url 中删除 index.php。我可以像http://localhost/trackstar/ 那样访问根页面而不是http://localhost/trackstar/index.php,但是一旦我尝试访问另一个页面,如http://localhost/trackstar/project 或任何其他页面,我总是会在index.php 页面结束。但是打开http://localhost/trackstar/index.php/project 可以。
我正在使用 WAMP 服务器。配置如下。
启用了 apache 中的重写模块。
配置main:
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'commentfeed' => array('comment/feed', 'urlSuffix' => '.xml', 'caseSensitive' => false),
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'showScriptName' => false,
),
.htaccess 在项目的根文件夹中:
Options +FollowSymlinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
我也加了httpd.conf,虽然我觉得不是很必要:
<Directory "c:/wamp/www/TrackStar/">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
我在.htaccess 中尝试了几种额外参数的组合,但我一直被重定向到我的index.php 页面。
关于为什么这不起作用的任何想法?
编辑:
由于我被重定向,RewriteCond 中的检查不成功,换句话说,REQUEST_FILENAME 没有作为目录或文件找到。也许我的目录结构有问题?
TrackStar\protected\views\project 目录,例如我试图通过http://localhost/trackstar/project 访问的页面。我的Yii 框架文件位于www 文件夹上方的目录中。
【问题讨论】:
-
您的网址是否正确生成?还是应用程序将您重定向到 index.php?
-
@PeterM:我的浏览器显示
http://localhost/trackstar/project,但我在index.php页面上。 -
.htaccess 是否与 index.php 位于同一目录?
-
@CreatoR:是的,在
www\Trackstar中,还有另一个.htaccess文件位于www\Trackstar\protected中,内容为deny from all。
标签: apache .htaccess yii url-rewriting