在将后端/Web转换为管理员和前端/Web 到 MyProject/ 时找不到 common/web/js 和 CSS



在我的 Yii2 项目中,我将 URL 从 myproject/backend/web 重写为 myproject/admin,从 myproject/frontend/web 重写为 myproject/。

前端工作正常,但在后端,通用/web/css/和通用/web/js/没有加载,我所有这些都重定向到前端并给出404页面未找到错误。

我已经检查了css和js的路径,它是正确的,如下所示: myproject/common/web/css/style.css.所有CSS和JS都加载了正确的路径,但它重定向到其他地方。

我使用以下代码进行重写:

我已经添加了这个 .htaccess :

RewriteEngine On
# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend)/web/ - [L]
# Handle the case of backend, skip ([S=1]) the following rule, if current matched
RewriteRule ^admin(/(.*))?$ backend/web/$2 [S=1]
# handle the case of frontend
RewriteRule .* frontend/web/$0
# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php

我在后端/配置/主中添加了这两行.php:

'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'scriptUrl'=> ($_SERVER['HTTP_HOST'] == "localhost") ? '/chiefsRS/admin' : '/admin',
'rules' => [
'login'=>'site/login',
'dashboard'=>'site/index',
]
],
'request' => [
'baseUrl'=>($_SERVER['HTTP_HOST'] == "localhost") ? '/myproject/admin' : '/admin',        
],

我在前端/配置/主中添加了这两行.php:

'request' => [
'baseUrl'=> ($_SERVER['HTTP_HOST'] == "localhost") ? '/myproject' : '',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'scriptUrl'=>($_SERVER['HTTP_HOST'] == "localhost") ? '/myproject' : '',
'rules' => [
'home'=>'site/index',
]
]

在我的本地服务器中,一些来自公共加载的 css 和一些给出 404 错误。 在实时服务器中,来自 common/web 的所有 css 和 js 都给了我 404 页面未找到错误。 错误页面有前端的导航栏,所以我认为所有的 css 和 js 都重定向到前端。

我的 .htaccess 文件有问题。我更改了我的htaccess,如下所示:

RewriteEngine On
RewriteRule ^(common)/ - [L]
# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend)/web/ - [L]
# Handle the case of backend, skip ([S=1]) the following rule, if current matched
RewriteRule ^admin(/(.*))?$ backend/web/$2 [S=1]

# handle the case of frontend
RewriteRule .* frontend/web/$0
# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php

相关内容

最新更新