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

时间:2013-03-11 22:48:55

标签: php .htaccess codeigniter routing

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

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

我正在使用xampp,因此我访问该网站的网址是

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

现在应用上面的.htaccess文件后,我尝试了没有index.php这样的

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

但不是工作,而是将我重定向到此网址

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;

7 个答案:

答案 0 :(得分:15)

这对我很有用:

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

答案 1 :(得分:7)

尝试将RewriteBase定义为/ projects / zorkif_nextgen

RewriteBase /projects/zorkif_nextgen

答案 2 :(得分:2)

尝试以下

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]

答案 3 :(得分:2)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

答案 4 :(得分:1)

你可以试试这个

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

将来阅读这将对您有所帮助Codeigniter remove index php from url using htaccess

答案 5 :(得分:1)

您可以查看config / routes.php。

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

答案 6 :(得分:-1)

请勿使用.htaccess文件从您的网址中删除index.php。这是配置中的问题。请特别注意$config['base_url']$config['index_page']