php - 代码点火器 | .htaccess 从 url 中删除 index.php

标签 php .htaccess codeigniter routing

好的,我完全按照 codeigniter 文档中的要求做了,创建了新文件 .htaccess

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

我正在使用 xampp,所以我访问网站的 url 是

http://localhost:12/projects/zorkif_nextgen/index.php/main

现在在应用了上面的 .htaccess 文件之后,我像这样在没有 index.php 的情况下尝试了它

http://localhost:12/projects/zorkif_nextgen/main

但是它没有工作,而是将我重定向到这个 url

http://localhost:12/xampp

如何解决这个问题?

另外,在尝试 .htaccess 后我的页面出现错误

出现在页面顶部的消息,

 Error Occured.
Warning!. Make sure you perform the correct action.
The Action has been completed Successfully. 

编辑:

这是我的一些 config.php 文件设置

$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['enable_hooks'] = FALSE;
$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'; // experimental not currently in use
$config['sess_cookie_name']     = 'zk_ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie']  = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'sys_ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['rewrite_short_tags'] = FALSE;

最佳答案

这对我来说效果很好:

1- 使用以下内容在根文件夹中创建 .htaccess 文件

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

2- 从配置文件更改 $config['index_page'] = 'index.php';$config['index_page'] = '';

关于php - 代码点火器 | .htaccess 从 url 中删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15350137/

相关文章:

php - Symfony : The service . .. 依赖于不存在的参数 kernel.secret

php - 按标签选择博客文章

apache - 通过 httpd.conf/htaccess 重定向目录中除一个文件之外的所有文件

.htaccess - htaccess陷入无限循环

php - 如何在加载 View 之前将数组从 Controller 传递到包含 CSS 的 PHP 文件?

php - CakePhp 将评论与帖子相关联

php - 表单中的数据未使用 php 添加到数据库表中

.htaccess - htaccess 只允许查看 JS 和 CSS 文件?

php - 使用 array() 在 codeigniter 中加载多个库。第一个库可以工作,但第二个库不行

Codeigniter - 以 DOC 格式导出数据库数据