首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将后端/web转换为admin,将前端/web转换为myproject/时,找不到common/web/js和css 404

将后端/web转换为admin,将前端/web转换为myproject/时,找不到common/web/js和css 404
EN

Stack Overflow用户
提问于 2019-06-18 22:34:38
回答 1查看 46关注 0票数 0

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

前端运行良好,但在后端,公共/web/css/和common/web/js/没有加载,我将所有这些重定向到前端,并给出404页面未找到错误。

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

我已经使用了以下代码来重写:

我添加了这个.htaccess:

代码语言:javascript
复制
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

我在backend/config/main.php中添加了这两行:

代码语言:javascript
复制
'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',        
               ],

我在前端/config/main.php中添加了这两行:

代码语言:javascript
复制
'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都重定向到了前端。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-20 19:17:31

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

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56651540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档