【问题标题】:Yii Framework: Instructions to hide index.php entry script aren't workingYii 框架:隐藏 index.php 条目脚本的说明不起作用
【发布时间】:2014-09-06 01:16:23
【问题描述】:

我正在尝试通过删除 index.php 条目脚本来整理我的网站 URL。有一个记录的方法可以做到这一点,在这里找到:http://www.yiiframework.com/doc/guide/1.1/en/topics.url

说明在 Yii 项目配置文件中将“showScriptName”设置为 false。

他们还说要在您的 Apache 配置中启用重写模块。我在 WAMP 的 httpd 文件中手动启用了它。 See here。我也可以通过系统托盘界面完成。

保存后,我通过服务器重新启动。

最后,(这是我最不确定的,但我从说明中复制了它)我在 Yii 项目的受保护文件夹中的 .htaccess 文件中添加了一些行。

允许覆盖所有 重写引擎开启 # 如果目录或文件存在,直接使用 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # 否则转发到 index.php 重写规则。索引.php

尽管如此,我的每一页都收到 Not Found 错误。我不确定发生了什么,或者我没有做些什么来正确启用它。

谢谢。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite yii


    【解决方案1】:

    .htaccess 内容位于根目录中的 .htaccess 文件中,而不是受保护的文件夹中。然后它应该可以工作。来自http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x 阅读:

    我们可以创建文件/wwwroot/blog/.htaccess,内容如下。

    【讨论】:

    • 那一定是我看错了。我做了你所说的和@visevo 所做的,现在我得到了想要的效果。谢谢。
    【解决方案2】:

    以下设置是我用于每个 Yii 项目的设置。试一试。

    .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
    </ifModule>
    

    /protected/config/main.php

    'urlManager'=>array(
        'showScriptName'=>false,
    

    【讨论】:

    • 谢谢。这似乎是一段比我更好的代码。
    猜你喜欢
    • 2013-06-13
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 2012-08-13
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多