php - 尝试使用 Yii 2 启用漂亮的 URL 时出错

标签 php apache yii yii2

我正在使用 Yii 2 并且我想启用 pretty URL's 以便我可以访问以下内容:

www.example.com/controller/method

根据我的发现,您在 config/web.phpcomponents 部分添加了以下代码:

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'enableStrictParsing' => true,
    'rules' => [

    ],
],

但是,当我加载索引页面时,我现在收到此错误:

exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request: site/error' in *************\vendor\yiisoft\yii2\base\Controller.php:122

还有这个之前的异常(exception):

exception 'yii\web\NotFoundHttpException' with message 'Page not found.' in ***************************\vendor\yiisoft\yii2\web\Request.php:187

这是我的.htaccess 文件:

# use mod_rewrite for pretty URL support
RewriteEngine on

# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward the request to index.php
RewriteRule . index.php

我是否遗漏了规则部分中的某些内容,或者我在这里做错了什么?

最佳答案

尝试删除 'enableStrictParsing' => true,

enableStrictParsing:该属性决定是否启用严格的请求解析。如果启用严格解析,传入请求的 URL 必须至少匹配其中一条规则才能被视为有效请求,否则将抛出 yii\web\NotFoundHttpException。如果禁用严格解析,则当没有规则匹配请求的 URL 时,URL 的路径信息部分将被视为请求的路由。

关于php - 尝试使用 Yii 2 启用漂亮的 URL 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27124544/

相关文章:

apache - SOLR 5.0.0 的 HTTP 状态 503 错误

postgresql - Yii 框架和 PostgreSQL 分区表 - 0 行受影响

php - yii向第三张表插入数据

php - 如何使用 CodeIgniter 对数据库值进行降序排序?

php - 使用内爆数组 PHP 更新 MySQL 记录

javascript - 从一种 PHP 表单涉及的多个选择框中获取至少一个值

php - 如何在phpMyAdmin中编写存储过程?

java - Apache Camel 多线程处理

apache - 如何使基本身份验证排除重写的 URL

php - 如何在 PostgreSQL array_append() 中使用数组变量?