【发布时间】:2014-05-24 11:44:15
【问题描述】:
嗯,PHP 时代。
我的客户希望我使用 Yii2 作为他项目的框架。
我启动并运行它。没问题。我通过 composer 使用了高级模板。
将我的网络根设置为 /frontend/web 等。
现在,我想使用这种 url 格式
website.com/messages/ 或 website.com/messages/tom...等
现在的方式是设置显示 website.com/index.php?r=messages/index...
我找到了这个文档...
https://github.com/yiisoft/yii2/blob/master/docs/guide/url.md
但我似乎无法弄清楚。
这是我的步骤...
我将我的 apache 服务器配置为指向 /usr/www/payroll/frontend/web/
我在我的网络文件夹中添加了一个包含此内容的 .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”。它似乎捕获了请求并对其进行了修改。
'components'=>[
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => 'false'
],
],
例如,如果我输入 website.com,您可以看到它会将 /site/index 添加到 url。 (如果没有激活 url 组件,它只会添加 /index.php?site/index)
所以,显然对 url 进行了修改(通过 UrlManager),但我收到 404 错误
我的想法已经不多了。我是 Php、Apache 和 Yii2 的新手。任何帮助,不胜感激。
谢谢
【问题讨论】:
-
我不明白任何网站页面都有效吗?
-
如果我将组件代码存根添加到我的配置文件中,它不会。
-
无论我做什么,它都不会显示 website.com/controller/action....如果我将组件代码添加到我的配置中,它甚至无法正常工作。 . 含义,website.com/index.php?r=controller/action
-
'showScriptName' => 'false' 应该有 'showScriptName' => false
-
抱歉,这里打错了,不是代码。在我的代码中,它显示 false 而不是 'false'。
标签: php apache .htaccess yii-components yii2