7

好的,我完全按照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

但它不是工作,而是将我重定向到这个 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;
4

7 回答 7

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

于 2013-03-12T03:14:24.900 回答
7

尝试将 RewriteBase 定义为 /projects/zorkif_nextgen

RewriteBase /projects/zorkif_nextgen
于 2013-03-11T23:30:13.777 回答
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]
于 2013-03-11T22:52:12.480 回答
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]
于 2014-12-03T15:02:27.647 回答
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 使用 htaccess 从 url 中删除索引 php

于 2014-01-20T15:40:37.437 回答
1

您可能已经查看了 config/routes.php。

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

于 2014-07-09T13:38:40.797 回答
-1

不要使用 .htaccess 文件从您的 URL 中删除 index.php。这是您的配置中的一个问题。具体看$config['base_url']$config['index_page']

于 2013-03-11T22:54:43.870 回答