Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试启用漂亮URL时出错';他和Yii 2在一起_Php_Apache_Yii_Yii2 - Fatal编程技术网

Php 尝试启用漂亮URL时出错';他和Yii 2在一起

Php 尝试启用漂亮URL时出错';他和Yii 2在一起,php,apache,yii,yii2,Php,Apache,Yii,Yii2,我正在使用yii2,我想启用pretty-URL的,这样我就可以访问如下内容: www.example.com/controller/method 根据我的发现,您在config/web.php的组件部分添加了以下代码: 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'enableStrictParsing' => true, 'rules'

我正在使用
yii2
,我想启用
pretty-URL的
,这样我就可以访问如下内容:

www.example.com/controller/method
根据我的发现,您在
config/web.php
的组件部分添加了以下代码:

'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 '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的路径信息部分将被视为请求的路由。

您没有任何规则,因此它们都不匹配,因此我必须为我想要的每个路由专门添加一条规则,并且它不会自动按我想要的方式工作。是的,完全正确。我个人不使用enableStrictParsing,如果规则中的规则不匹配,它将遵循正常路径控制器/操作。