【问题标题】:Codeigniter admin application in subfolder shows 404 error page子文件夹中的 Codeigniter 管理应用程序显示 404 错误页面
【发布时间】:2019-11-25 11:18:45
【问题描述】:

我有以下问题..

我已经创建了位于 sub.domain.com 的主 codeigniter 网站,并且我还在 sub.domain.com/admin 中创建了另一个 codeigniter 应用程序(管理员) ..

*请注意,我没有使用 HMVC 模型,以防有人提到它......

问题是,当我尝试访问 /admin url 时,出现错误 404 重定向问题。

这是我的主要文件和一些额外的东西我要提到:

.htaccess 文件:

Options -Indexes
Options +FollowSymLinks

# Indexes default
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /admin
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php/$1
</IfModule>

我的 routes.php 文件:

/**
* Users login - logout
*/
$route['login'] = 'users/users/login';
$route['logout'] = 'users/users/logout'; //Controller located in subfolder

$route['users'] = 'users/users';
$route['users/(:any)'] = 'users/users/$1';
/**
* Redirect any URI after default url
*/
$route['pages/(:any)'] = 'pages/$1';

/**
* Other routes
*/
$route['(:any)'] = 'pages';
$route['default_controller'] = 'pages';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

我的 header.php 文件中也有这个,如果未登录,我会在其中重定向用户登录等.. 等等..

if (!$this->ion_auth->logged_in() && $this->uri->segment(1) !== 'login') {              
    redirect('login');
} elseif( $this->ion_auth->logged_in() && !$this->ion_auth->is_admin($this->ion_auth->get_user_id()) ){
    redirect('logout');
}

应用程序/控制器结构如下:

Controllers
-Customers
--Customers.php
-Users
--Users.php
-Pages.php
etc..etc..

我已经尝试了所有方法(.htaccess、RewriteBase /admin 等),但仍然没有任何效果..

有什么想法吗?谢谢...

【问题讨论】:

  • 您写道,您有主应用程序和另一个应用程序 - 这可以通过不同的方式完成,答案取决于它。请在上层显示您的文件夹和文件结构(当文件夹应用程序、系统、www 等时)。文件夹 'admin' = 'application' 文件夹,其他 'project' 或主应用程序中的文件夹/控制器?
  • @ElenaVasilenko 在 sub.domain.com 下的结构是:(admin, application, assets, system, .htaccess, etc.. etc..) 和 sub.domain.com/admin 下的结构是:(应用程序、资产、系统、.htaccess 等等……等等)如果这就是你的意思!
  • 是的,我就是这个意思。我在下面的答案中的决定。

标签: php .htaccess codeigniter redirect


【解决方案1】:

试试这个:

.htaccess 在主应用程序中:

AddDefaultCharset UTF-8
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)admin(.*)$ /admin/index.php$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php/$1
</IfModule>

.htaccess in /admin:

AddDefaultCharset UTF-8
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) /admin/index.php/$1
</IfModule>

【讨论】:

  • 不。还是一样.. 如果我检查了日志有帮助,我会看到:ERROR - 2019-07-16 22:33:01 --> 404 Page Not Found: Users/users 此外如果我从 header.php 中删除脚本,它有点工作.. 但我仍然无法转到位于子文件夹中的控制器.. 我还尝试了父文件夹的不同名称,例如:users.php 是找到了..还是什么都没有..
  • @Citer 尝试将您的控制器文件夹和子文件夹重命名为小写,仅文件夹和子文件夹:controllers -customers --Customers.php -users --Users.php -Pages.php etc..etc..
猜你喜欢
  • 2012-07-12
  • 2015-03-06
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
  • 1970-01-01
  • 2017-02-21
  • 1970-01-01
相关资源
最近更新 更多