php - CodeIgniter 仅显示默认 Controller

标签 php .htaccess codeigniter

我在本地 WAMP 中使用 Codeigniter。这里的代码工作正常。但我在 Cpanel 中上传(在 example.com 中,文件夹名称为“mysite”)。在那里我改变了,

  • db_name (config/database.php)
  • db_user_name (config/database.php)
  • db_password (config/database.php)
  • base_url 为 http://example.com/mysite (配置/配置.php)
  • uri_protocol 作为 REQUEST_URI (config/config.php)

并且还将 .htaccess(mysite/.htaccess) 更改为,

<IfModule mod_rewrite.c>

RewriteEngine On

# Set the rewritebase to your CI installation folder
RewriteBase /mysite/


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

但不在 mysite/application/.htaccess 中。它是空的。

问题是,如果我去 http://example.com/mysite ,它正确显示默认页面。但是,如果我单击任何链接 ( http://example.com/mysite/user/signin ),它会显示相同的默认页面。但 URL 已更改。

请帮帮我...

config.php

$config['base_url'] = 'http://example.com/mysite';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['allow_get_array']      = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger']   = 'c';
$config['function_trigger']     = 'm';
$config['directory_trigger']    = 'd';
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['cache_path'] = '';
$config['encryption_key'] = '***';
$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";
$config['cookie_secure']    = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';
define('CSS_FOLDER' , 'application/assets/css');
define('DEFAULT_IMAGE_URL' , 'application/assets/images/default');

routes.php

$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['user/(:any)'] = 'user/index';

最佳答案

$config['base_url'] = 'http://example.com/mysite/';

优于:

$config['base_url'] = 'http://example.com/mysite';

试试这个:

RewriteBase /

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]

关于php - CodeIgniter 仅显示默认 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17676920/

相关文章:

codeigniter 获取两个相同值的位置

php - 发生验证错误时 Symfony2 表单字段未更新

php - PHP 文件中的 Symfony2 数据库配置

javascript - 单击提交按钮时未完成验证

.htaccess - 使用单页应用程序重定向到 .htaccess 上的 https

regex - .htaccess - 递归地将斜杠映射到下划线

php - 在 CodeIgniter 中显示 404 错误的 View

php - 如何在 Codeigniter 中将事件 session ID 解析为外键

php - GMaps api 地理编码奇怪的行为

php - 在 IIS7 上使用 web.config 删除 .php 扩展名