如何在yii框架中从url隐藏index.php


How to hide index.php from url in yii framework

在Apache服务器上的Yii中实现了我的项目。它运行良好。我想在生产服务器和本地服务器的url中隐藏index.php,它们都在Apache上运行。

我尝试了以下配置。'show Script Name'=>false,

但它不起作用。

属性"showScriptName"应该没有空格。

array(
    ......
    'components'=>array(
        ......
        'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false
        ),
    ),
);

不要忘记为apache启用mod_rewrite并使用在webroot目录中创建.htaccess文件

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

我还建议您阅读本UrlManager指南:http://www.yiiframework.com/doc/guide/1.1/en/topics.url