dongyo1818 2019-06-18 14:34
浏览 104
已采纳

将backend / web转换为admin和frontend / web到myproject时找不到common / web / js和css 404

In my Yii2 project,I have rewrite the URL from myproject/backend/web to myproject/admin and from myproject/frontend/web to myproject/.

Frontend works fine but in backend the common/web/css/ and common/web/js/ is not loading and I this all these redirect to frontend and gives 404 page not found error.

I have checked the path of css and js and it's correct as below : myproject/common/web/css/style.css. all css and js loaded with correct paths but it redirects to some other place.

I have used below code for rewriting :

I have added this .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

I have added this two lines in backend/config/main.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',        
               ],

I have added this two lines in frontend/config/main.php :

'request' => [
            'baseUrl'=> ($_SERVER['HTTP_HOST'] == "localhost") ? '/myproject' : '',

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

In my local server some css from common loaded and some gives 404 error. In live server all css and js from common/web gives me 404 page not found error. And error page has navbar of frontend so i think all css and js are redirecting to fronted.

  • 写回答

1条回答 默认 最新

  • dongxuanchao1425 2019-06-20 11:17
    关注

    I have an issue with my .htaccess file. I changed my htaccess as follows :

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测