php - 只有默认控制器在 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
谁能知道我们如何处理其他路线。谢谢
解决方案
我的查询字符串已启用,并且对于这样的重定向
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
推荐阅读
- matlab - 将直流电机添加到 Simscape 模型
- sql - 如何在合并语句中将插入与从其他表中选择一起使用?
- android - Google Play:从“开放测试”升级到“生产”时,评分和评论会变成什么?
- python - 来自一个 docker 文件的多个 python 图像
- java - Spring Controller ModelAndView 测试 MockMvc 空响应
- python - 模型 = tf.keras.models.load_model()
- java - 二元运算符的错误操作类型'||' 第一种类型:布尔值,第二种类型:int?
- python - python-pptx:将图表的值轴设置为在 0 处交叉
- ios - FLUTTER IOS:我的应用在聚光灯下没有同名
- java - 带有 module-info.java 的 maven-surefire-plugin 导致 VM 崩溃