无需在Yii上编写index.php

时间:2014-01-02 11:38:28

标签: php .htaccess yii frameworks

我在我的WAMP环境中设置了Yii 1.1.x,但一切正常但我仍然需要在URL中使用index.php才能使路由工作。

我的WAMP配置已启用Mod重写。

任何人都可以解释我需要修改哪些内容以允许我在URL本身没有index.php的情况下运行应用程序吗?

我的Yii配置如下:

// uncomment the following to enable URLs in path-format        
urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
            '<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

 # if a directory or a file exists, use it directly
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

 # otherwise forward it to index.php
 RewriteRule . index.php

1 个答案:

答案 0 :(得分:1)

.htaccess 文件更改为此

<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Don't perform redirects for files and directories that exist:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For everything else, redirect to index.php:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</ifModule>

注意: - 将其保存为 www / yourProject / .htaccess