从Codeigniter中的URL中删除index.php

从Codeigniter中的URL中删除index.php,codeigniter,mod-rewrite,Codeigniter,Mod Rewrite,我已经做了很多次了。但是,我再次被困在这里(在另一台服务器中),无法找出问题所在 已完成htaccess编辑 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /glt.me/CI/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /glt.me/CI/index.php/$1 [L] <

我已经做了很多次了。但是,我再次被困在这里(在另一台服务器中),无法找出问题所在

已完成htaccess编辑

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /glt.me/CI/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /glt.me/CI/index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

首先检查您的apache是否支持
mod\u rewrite
。如果是,则添加一个
.htaccess
文件。我的codeigniter.htaccess文件是:

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

最后,在您的配置文件中,更改您的基本url,如果已添加,则从中删除index.php。

这是一种简单的方法,可以很好地从url中删除index.php

RewriteEngine on
RewriteCond $1 !^(index\.php|uploads|css|js|lib|img|bootstrap|robots\.txt)
RewriteRule ^(.*)$ /manage/index.php/$1 [L]

instead of manage put your own application folder name.

使用以下htaccess代码从codeigniter url中删除index.php

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

虽然您的客户确认重写模块正在工作,但您自己不确认的是,在项目的根目录上用下面的代码创建一个php文件,并尝试浏览该文件

<?php
 if( !function_exists('apache_get_modules')){
        echo 'Rewrite module not available';
 }else{
    if(in_array('mod_rewrite',apache_get_modules()))
        echo 'Rewrite module enabled';
 }

我想在这里做贡献,因为我自己也遇到了麻烦。我使用IIS5.1仅用于开发(强烈不推荐!)

1-确保config.php文件具有:

$config['index_page'] = '';
2-我的应用程序不在根文件夹中,它位于localhost/CodeIgniter/。我将config.php更新为:

$config['base_url'] = 'http://localhost/CodeIgniter/';
3-你需要修改重写功能。这是嵌入在大多数服务器中的,但IIS5.1需要一个单独的工具。我使用了:由micronovae编写的IIS Mod Rewrite。只要您在本地主机上使用它,它是免费的

我输入以下代码(而不是CodeIgniter,输入文件夹的名称):

如果您的应用程序位于根目录下,那么您应该使用的代码应该是:

RewriteEngine on
RewriteCond $0 !^(css|js|swf|images|system|tools|themes|index\.php) [NC]
RewriteRule ^(.*)$ index.php/$1 [L]

希望有帮助。

在WAMP环境中,从Codeigniter的url中删除index.php只需要三个步骤

1) 与应用程序持有者并行创建.htacess文件,只需复制以下代码即可:

RewriteEngine On
RewriteBase /CodeIgniter/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
2) 在应用程序文件夹的config.php中将$config['index_page']更改为空,如下所示:

$config['index_page'] = '';
3) 启用apache的“重写\u模块”

重新启动apache并完成它


详细信息:

您需要检查错误日志以查看导致错误的原因it@JonLin-猜谜更有趣。检查日志就像阅读文档:只有弱者才会这样做;-)工作。已从RewriteRulke行中删除域。RewriteRule^(.*)$/CI/index.php?/$1[L]我已经尝试了这段代码
RewriteRule^(.*)$index.php/$1[L]
,但我仍然可以以两种方式查看页面,并且会产生SEO错误,即重复的标题标记和重复的元描述
RewriteEngine on
RewriteCond $0 !^(css|js|swf|images|system|tools|themes|index\.php) [NC]
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteEngine On
RewriteBase /CodeIgniter/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
$config['index_page'] = '';