【问题标题】:How to remove index.php from baseUrl Yii如何从 baseUrl Yii 中删除 index.php
【发布时间】:2014-10-29 19:49:30
【问题描述】:

我已经使用 .htaccess 从 URL 中删除了 index.php,还使用 ​​main/config.php 中的 URL 管理删除了控制器名称“站点”。

但是当我echo 基础url(Yii::app()->baseUrl); 它打印我与index.php。谁能告诉我如何删除它?

【问题讨论】:

  • 你真的在 uri 中看到了index.php 吗?如果不是,为什么url(Yii::app()->baseUrl) 返回index.php 会让你感到不安?如果你想检查你所在的页面,你应该检查控制器操作Yii::app()->controller->action->id
  • 当我做一些重定向时,例如: Home 这会让我回到我的网站.com/index.php 而不是 mywebsite.com
  • 好吧,我明白了,实际上是 homeUrl 将我转到了 mywebsite.com/index.php,因为 baseUrl 工作正常。

标签: php yii url-rewriting


【解决方案1】:

在 UrlManager 中将 showScriptName 设置为 false 并将 urlFormat 设置为路径:

'urlManager' => array(
    'urlFormat' => 'path',
    'showScriptName' => false,
    [...]
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-22
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    相关资源
    最近更新 更多