首页 > 解决方案 > 只有默认控制器在 CodeIgniter 3 中工作

问题描述

在服务器上,我创建了一个放置我的 CodeIgniter 3 代码的子域。无论我放置什么控制器路径,它的默认控制器都可以正常工作,但是有很多帖子。错误显示找不到 404 页面。我尝试了多种解决方案,但对我不起作用。我的 .htaccess 文件是

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

#ErrorDocument 404 /index.php

基本网址是

defined('BASE_URL') OR define('BASE_URL', (is_https() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/');
$config['base_url'] = BASE_URL;
$config['index_page'] = '';

我的路线是:

$route['default_controller'] = "our_menu";
$route['our_menu/menu'] = "our_menu/menu";
$route['product/:num'] = 'catalog/product_lookup';
$route['admin'] = 'admin/login';
$route['404_override'] = '';

我还通过删除除 default_controller 之外的其他路由来测试这一点。我的php版本是5.6

谁能知道我们如何处理其他路线。谢谢

标签: php.htaccesssubdomainconfigcodeigniter-3

解决方案


我的查询字符串已启用,并且对于这样的重定向

redirect('c=welcome &m=index', 'refresh');

和网址 index.php?c=our_menu&m=menu

或者如果更改config.php中的配置,那么您需要更改c and m 类似

$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

如果我将$config['enable_query_strings'] = TRUE更改为 $config['enable_query_strings'] = FALSE那么 URL 就像index.php/our_menu/menu


推荐阅读