[英]Yii2 doesn't find /backend/web after .htaccess changes
I'm trying to get an Yii2 advanced template up on a VPS.我正在尝试在 VPS 上获取 Yii2 高级模板。 Everything works fine in terms of algorithms and pathing until I try to enable 'pretty url' through config files and .htaccess.
在算法和路径方面一切正常,直到我尝试通过配置文件和 .htaccess 启用“漂亮的 url”。 It works perfectly for /frontend, but /backend can no longer be accessed.
它非常适用于 /frontend,但 /backend 无法再访问。 I'm still a newbie on .htaccess so any help would be appreciated.
我仍然是 .htaccess 的新手,因此我们将不胜感激。
Root .htaccess:根 .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule backend backend\.php [T=application/x-httpd-php]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
common\config\main.php (urlManager) common\config\main.php (urlManager)
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
frontend/web/.htaccess前端/web/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I've also tried changing the frontend/config/main.php basePath as such:我也试过改变 frontend/config/main.php basePath如下:
use yii\web\Request;
$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());
But to no avail, since I would only get a 500 error (and nothing else) while trying to access the server.但无济于事,因为我在尝试访问服务器时只会收到 500 错误(没有别的)。
Note: mode_rewrite has been enabled both through a2enmod and through apache2.conf.注意:mode_rewrite 已通过 a2enmod 和 apache2.conf 启用。
Yii2 advanced .htaccess configuration Yii2 高级 .htaccess 配置
.htaccess .htaccess
Options -Indexes
Options FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]
RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1
.htaccess - backend .htaccess - 后端
# use mode 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
.htaccess - frontend .htaccess - 前端
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Включаем mod_rewrite и перенаправляем со слэша
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]
# Если это папка или файл, открываем ее/его
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# В противном случае перенаправляем на index.php
RewriteRule . index.php
</IfModule>
Hope it helps希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.