.htaccess 您访问的页面不存在!

ccgok5k5  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(128)

我已经使用public const CI_VERSION = '4.1.9';安装了全新的Codeigniter 4,并配置了基本步骤

步骤1

app > app.php > public $baseURL = 'http://121.52.xxx.xxx/faculty_portal/';
removed index.php from $indexPage='';
public $uriProtocol = 'PATH_INFO';

步骤2

重命名.env文件并设置开发模式

CI_ENVIRONMENT = development

步骤3

从公共文件夹〉将index.php和.htaccess文件移到主文件夹

.htaccess file has default configuration

而index.php文件

$pathsConfig = FCPATH . 'app/Config/Paths.php';
require realpath($pathsConfig) ?: $pathsConfig;
$paths = new Config\Paths();
$bootstrap = rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php';

此处随附错误图像。
第一次
我正在尝试安装它在子文件夹是faculty_portal尊敬的社区请指导我哪里做错了。您的指导/帮助将是非常感谢。

问题已更新
路线代码

namespace Config;
$routes = Services::routes();

if (file_exists(SYSTEMPATH . 'Config/Routes.php')) {
    require SYSTEMPATH . 'Config/Routes.php';
}

$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);

$routes->get('/', 'Home::index');
$routes->get('/test', 'Home::test');

if (file_exists(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) {
    require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}

在这里我想访问/测试路由
使用http://121.52.XXX.XXX/faculty_portal/public/test的url访问

主控制器

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        return view('home_view');
    }

    public function test(){
        echo "hello";exit;
    }

}

公用文件夹中的index.php文件

$minPhpVersion = '7.4'; // If you update this, don't forget to update `spark`.
if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
    $message = sprintf(
        'Your PHP version must be %s or higher to run CodeIgniter. Current version: %s',
        $minPhpVersion,
        PHP_VERSION
    );

    exit($message);
}

define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);

chdir(FCPATH);
require FCPATH . '../app/Config/Paths.php';
$paths = new Config\Paths();
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php';

require_once SYSTEMPATH . 'Config/DotEnv.php';
(new CodeIgniter\Config\DotEnv(ROOTPATH))->load();
$app = Config\Services::codeigniter();
$app->initialize();
$context = is_cli() ? 'php-cli' : 'web';
$app->setContext($context);
$app->run();

以下是错误消息的外观
第一次

kfgdxczn

kfgdxczn1#

对于[v4.2.1],您不需要移动主目录中的index.php。请将其保存在公共文件夹中。
并且index.php中的第20行必须

require FCPATH . '../app/Config/Paths.php';

对于应用程序-〉配置-〉App.php

public $uriProtocol = 'REQUEST_URI';

对于应用程序-〉配置-〉Routes.php

$routes->setAutoRoute(false);

对于应用程序-〉配置-〉Feature.php

public bool $autoRoutesImproved = true;

对于主目录中的.htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sitename.com$
RewriteRule (.*) https://www.sitename.com/$1 [R=301,L] 

DirectoryIndex /public/index.php
RewriteCond $1 !^(index\.php|images|assets|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R]
RewriteRule ^(.*)$ ./public/index.php/$1 [L]

对于公用文件夹.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sitename.com$
RewriteRule (.*) https://www.sitename.com/$1 [R=301,L]
RewriteCond $1 !^(index\.php|images|assets|doc|data|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*[^/])$ /$1/ [L,R]
</IfModule>

相关问题