Php CodeIgniter仅显示默认控制器
我正在本地WAMP中使用Codeigniter。这里的代码运行良好。但我在Cpanel中上传(example.com内部,文件夹名为“Php CodeIgniter仅显示默认控制器,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我正在本地WAMP中使用Codeigniter。这里的代码运行良好。但我在Cpanel中上传(example.com内部,文件夹名为“mysite”)。在那里我变成了 数据库名称(config/database.php) db\u用户名(config/database.php) db_密码(config/database.php) 基本url(config/config.php) uri协议作为请求uri(config/config.php) 并将.htaccess(mysite/.htac
mysite
”)。在那里我变成了
- 数据库名称(config/database.php)
- db\u用户名(config/database.php)
- db_密码(config/database.php)
- 基本url(config/config.php)
- uri协议作为请求uri(config/config.php)
.htaccess
(mysite/.htaccess)更改为
routes.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');
$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['user/(:any)'] = 'user/index';
如果您计划在服务器上使用子文件夹,请在本地WAMP上执行相同的操作。这样,您可以在将其发送到服务器之前对其进行测试 我很久以前就在使用CI了,但我认为您必须在一些配置文件中添加
mysite/
请参阅:.htaccess代码
将默认配置恢复为config.php,希望这对您有所帮助
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
有时“原始路径信息”会修复此问题。因此,您还可以通过将uri\u协议更改为“原始路径\u信息”重试
及
基本url应该是绝对的
$config['base_url'] = "http://example.com/mysite/";
当URI不存在时,可以告诉CodeIgniter加载默认控制器,就像只请求站点根URL时一样。因此,一旦在routes.php中将默认conroller“welcome”替换为conrtoller,它可能会帮助您
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
试试这个htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
您还应该创建名为user的控制器,并且该控制器应该具有函数签名 我使用了下面的.htaccess文件,它适用于我的cpanel
# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php
# Rewrite engine
RewriteEngine On
# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
除去
在routes.php文件中。user/signin符合上述条件,这就是为什么CI将请求路由到user/index而不是“user”controller“signin”函数的原因
通过该路由配置,您试图实现什么目标?打开config.php并执行以下操作:
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
在某些情况下,uri_协议的默认设置无法正常工作。
替换
$config['uri_protocol']=“自动”
通过
$config['uri\u protocol']=“请求\u uri”
HTACCESS
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
优于:
$config['base_url'] = 'http://example.com/mysite';
试试这个:
RewriteBase /
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
我也面临同样的问题..当我使用
$config['uri_protocol'] = 'AUTO';
在config.php中..尝试使用AUTO和PATH_INFO进行相同的设置
确保apache中的“重写”模块处于启用状态,不要在.htaccess文件中写入任何内容,并删除$route['user/(:any)]='user/index';行和一件非常重要的事情,确保在您的服务器mod rewrite扩展中启用me
希望这对您有所帮助您需要考虑的事情很少。使用codigniter框架设置项目时。以下是您必须进行更改的文件 1)。htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
$config['base_url'] = 'http://example.com/mysite/';
$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$db['default']['hostname'] = 'localhost'; // set your hostname
$db['default']['username'] = 'root'; // set database username
$db['default']['password'] = 'root'; //set database password
$db['default']['database'] = 'XYZ'; //set your database name
$db['default']['dbdriver'] = 'mysql';
$route['default_controller'] = "user"; //your default controller
$route['404_override'] = '';
2)application/config/config.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
$config['base_url'] = 'http://example.com/mysite/';
$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$db['default']['hostname'] = 'localhost'; // set your hostname
$db['default']['username'] = 'root'; // set database username
$db['default']['password'] = 'root'; //set database password
$db['default']['database'] = 'XYZ'; //set your database name
$db['default']['dbdriver'] = 'mysql';
$route['default_controller'] = "user"; //your default controller
$route['404_override'] = '';
3)application/config/database.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
$config['base_url'] = 'http://example.com/mysite/';
$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$db['default']['hostname'] = 'localhost'; // set your hostname
$db['default']['username'] = 'root'; // set database username
$db['default']['password'] = 'root'; //set database password
$db['default']['database'] = 'XYZ'; //set your database name
$db['default']['dbdriver'] = 'mysql';
$route['default_controller'] = "user"; //your default controller
$route['404_override'] = '';
4)application/config/routes.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]
$config['base_url'] = 'http://example.com/mysite/';
$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$db['default']['hostname'] = 'localhost'; // set your hostname
$db['default']['username'] = 'root'; // set database username
$db['default']['password'] = 'root'; //set database password
$db['default']['database'] = 'XYZ'; //set your database name
$db['default']['dbdriver'] = 'mysql';
$route['default_controller'] = "user"; //your default controller
$route['404_override'] = '';
注意:您的.htaccess文件必须位于根目录中。这里它应该在mysite文件夹中,我通过更改控制器文件名以大写字母开头解决了相同的问题 就像下载的默认“欢迎”控制器一样。试试这个
$config['uri_protocol'] = 'PATH_INFO';
$config['enable_query_strings'] = FALSE;
Httaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#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 [NC]
</IfModule>
重新启动发动机
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[NC]
你能给我们看一下config/config.php
和config/routes.php
?@bborisovs现在你可以看到…你的应用程序在哪里,在一个子文件夹中?@battleboot是的。example.com/mysite/application您是否尝试过@user2621595的答案?我投了赞成票。看来那个人会成功的。这是通常为我做的。查看我的问题文件将您的页面放入mysite/
文件夹中的WAMP
。若它能工作,问题不在CI中。我在本地WAMP中将我的文件夹名从mysite更改为mysite1,然后重试。很好用。我只更改了$config['base_url']='';所以CI是可以的。远程服务器有一些问题。您可以使用带有
的PHP文件查看服务器配置(可能没有mod_rewrite
和.htaccess
不起作用),您可以在application/logs
文件夹中检查CI日志中的信息,您可以检查write
权限以查看application/logs
和application/cache
,您可以检查apache日志中的信息,并且可以在PHP中激活错误消息(某些服务器不显示PHP错误)。这样你可以找到一些线索。对我来说,就是那个和模型。视图是OK小写的。妈妈不在乎这个案子。