【问题标题】:Unable to route the yii2 application in cpanel无法在 cpanel 中路由 yii2 应用程序
【发布时间】:2021-07-13 19:08:06
【问题描述】:

我已将我的 yii2 项目上传到我的cpanel。我的url 别名是xyz.com。下面是我的索引和ht访问文件

Index.html

<?php
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
    $uri = 'https://';
} else {
    $uri = 'http://';
}
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri.'/backend/dashboard/');
exit;
?>
Something is wrong :-(

Index.php

<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);

(new yii\web\Application($config))->run();

.htaccess

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

结构

在我的本地机器上。 URL 是localhost/backend/web。在我的生产服务器上,我要访问的URLxyz.com。但我只能访问xyz.com/backend/web

如果我点击 URL xyz.com,我会收到 Something is wrong :-( 消息。

如果我删除 index.html 文件,我会收到 This page isn’t working 消息。

如何访问它?任何帮助将不胜感激。

【问题讨论】:

    标签: php yii2 cpanel yii2-advanced-app


    【解决方案1】:

    在.htaccess

    <IfModule mod_rewrite.c> 
      RewriteEngine on
    
      RewriteRule ^(.*)$ backend/web/$1 [L] 
    </IfModule>
    

    【讨论】:

    • 我必须在哪一行添加它?
    • 顶级htaccess RewriteRule ^(.*)$ backend/web/$1 [L]
    猜你喜欢
    • 2019-08-11
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 2020-11-16
    • 2021-05-23
    • 2013-07-09
    • 1970-01-01
    相关资源
    最近更新 更多