Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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 Yii2使用漂亮的url返回404_Php_Apache_Yii2 - Fatal编程技术网

Php Yii2使用漂亮的url返回404

Php Yii2使用漂亮的url返回404,php,apache,yii2,Php,Apache,Yii2,我已经建立了一些Yii项目,但从未遇到过这个问题。我使用的是基本模板 Apache配置: <VirtualHost *:80> ServerName shop DocumentRoot "C:/xampp/htdocs/shop/web" <Directory "C:/xampp/htdocs/shop/web"> RewriteEngine on # If a directory or a file exists, use the request directly

我已经建立了一些Yii项目,但从未遇到过这个问题。我使用的是基本模板

Apache配置

<VirtualHost *:80>
ServerName shop
DocumentRoot "C:/xampp/htdocs/shop/web"

<Directory "C:/xampp/htdocs/shop/web">
 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

# if $showScriptName is false in UrlManager, do not allow accessing URLs with script name
RewriteRule ^index.php/ - [L,R=404]

# ...other settings...
</Directory>

</VirtualHost>
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false, 
    'rules' => [

     ],
],
奇怪的是,它让我可以访问
shop/gii
shop/product
,但如果我尝试在其他任何地方导航,我会得到一个

错误:找不到404对象


如果我删除
UrlManager
config,一切都会正常工作。

您需要删除该行

RewriteRule ^index.php/ - [L,R=404]
这就是问题所在,不允许您访问路由,我通常使用以下配置,从未遇到任何问题

<VirtualHost *:80>
       ServerName www.virtualdomain.local
       DocumentRoot "F:\xampp\htdocs\someproject\frontend\web"

       <Directory "F:\xampp\htdocs\someproject\frontend\web">
           # 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

           # use index.php as index file
           DirectoryIndex index.php

           # ...other settings...
       </Directory>
   </VirtualHost>

服务器名www.virtualdomain.local
DocumentRoot“F:\xampp\htdocs\someproject\frontend\web”
#使用mod_rewrite获得漂亮的URL支持
重新启动发动机
#如果存在目录或文件,请直接使用请求
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#否则,将请求转发到index.php
重写规则。index.php
#使用index.php作为索引文件
DirectoryIndex.php
#…其他设置。。。

谢谢-现在看,这和我在工作电脑上看到的一样。今天在家里开始了一个项目,必须设置apache+vhost,并直接从Yii2站点获取配置,可能会通知他们是的,你可以在github上添加问题,他们会为它添加补丁,但我认为可以通过在
index.php/
之前添加一个
/
来解决,就像这样
RewriteRule^/index.php/-[L,R=404]
@Kyle