【问题标题】:yii2 404 page not found when trying remove /web from url with .htaccess尝试使用 .htaccess 从 url 中删除 /web 时找不到 yii2 404 页面
【发布时间】:2017-03-22 13:09:41
【问题描述】:

我正在尝试使用 .htaccess 文件从 Yii2 基本模板中的 url 中删除此 /web。我已经找到了解决方案,但是出现了问题! 所以我之前找到的解决方案是:

1)放入根/web文件夹.htaccess:

RewriteEngine On RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

2)放入根文件夹.htaccess:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule (.*) /web/$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php

3)在request部分'baseUrl'=>''

中添加config/web.php

在执行第 2 步和第 3 步后出现问题。浏览器告诉:

未找到 在此服务器上未找到请求的 URL /web/index.php。 Apache/2.4.23 (Win64) PHP/5.6.25 服务器在 localhost 端口 80

当我在本地服务器(即 WAMP)上执行此操作时,所有这些都会发生。我试图把这个项目放在免费托管上,一切似乎都在那里工作。那么如何在我的本地服务器上解决这个问题呢?为什么会出现 404 错误?

【问题讨论】:

    标签: .htaccess yii2 yii2-basic-app


    【解决方案1】:

    尝试在根目录下 .htaccess 替换

    RewriteRule (.*) /web/$1
    

    RewriteRule ^(.*)$ /web/$1 [L,PT]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      • 2021-02-25
      • 1970-01-01
      • 2020-02-12
      • 1970-01-01
      相关资源
      最近更新 更多