CodeIgniter |.htaccess从url中删除index.php

CodeIgniter |.htaccess从url中删除index.php,php,.htaccess,codeigniter,routing,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文件

好的,我完全按照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之后,我的页面出现了错误

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
页面顶部显示消息

 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;
试试下面的方法

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

不要使用.htaccess文件从URL中删除index.php。这是配置中的一个问题。请特别查看
$config['base\u url']
$config['index\u page']

尝试将RewriteBase定义为/projects/zorkif\u nextgen

RewriteBase /projects/zorkif_nextgen

这对我来说很有效:

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']=''

您可以试试这个

<IfModule mod_rewrite.c> 
   RewriteEngine on 
   RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt) 
   RewriteRule ^(.*)$ /ci/index.php/$1 [L] 
</IfModule>

重新启动发动机
1美元^(索引\.php | images | swf | uploads | js | css | robots\.txt)
重写规则^(.*)$/ci/index.php/$1[L]

对于以后的阅读,这将帮助您查看config/routes.php


它可能已被设置为默认控制器。

感谢您的回复,我尝试了您的代码,但效果相同,我必须编写index.php使其工作。如果我尝试zorkif_nextgen/main,它会再次将我重定向到localhost:12/xampp??为什么它会将我重定向到主根?我已经尝试了其中的10个。你是为我的xampp工作的人。非常好。非常感谢。是的,它现在正如我所希望的那样工作:)你能告诉我如何在没有htaccess的情况下从url中删除index.php吗?准确完整的答案,而不是在根文件夹中使用
RewriteRule^(.*)/index.php/$1[L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]