删除codeigniter 2.1.0中的index.php

删除codeigniter 2.1.0中的index.php,php,codeigniter,Php,Codeigniter,我在google上尝试了所有与在codeigniter中从URL中删除index.php相关的方法,但没有一个解决方案对我有效 我使用的是codeigniter 2.1.0版 如何从URL中删除索引 谢谢您是否尝试过使用CodeIgniter用户指南中给出的示例 默认情况下,index.php文件将包含在URL中: example.com/index.php/news/article/my_article 通过将.htaccess文件与一些 简单的规则。下面是这样一个文件的示例,使用“负片”

我在google上尝试了所有与在codeigniter中从URL中删除index.php相关的方法,但没有一个解决方案对我有效 我使用的是codeigniter 2.1.0版 如何从URL中删除索引


谢谢

您是否尝试过使用CodeIgniter用户指南中给出的示例

默认情况下,index.php文件将包含在URL中:

example.com/index.php/news/article/my_article
通过将.htaccess文件与一些 简单的规则。下面是这样一个文件的示例,使用“负片” 方法,在该方法中,除了指定的项之外,所有内容都被重定向:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
在上面的示例中,除了index.php之外的任何HTTP请求, 图像和robots.txt被视为对index.php的请求 文件


应用程序/config.php中
确保

$config['index_page'] = "";
然后将其设置为您的
.htaccess
文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

重新启动发动机
重写基/
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
#此代码段阻止用户访问应用程序文件夹
#提交人:Fabdrol
#将“应用程序”重命名为应用程序文件夹名称。
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php

你都准备好了

除了Robert Stanley给出的.htaccess文件(参见他的答案),进入
application/config/config.php
,查找
$config['index\u page']=“index.php”
并将其替换为
$config['index\u page']=”

对我来说,Raphael Caixetas解决方案不起作用,但它确实起了作用:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 

我在apache2上测试了许多不同的主机,效果非常好

使用此htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
确保已使用
phpinfo()启用mod_rewirte

然后在config/config.php中执行此操作:

$config['index_page']   = '';
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';
如果它还不能工作,请尝试将
$config['uri_protocol']='AUTO'
更改为第40/54行
application/config/config.php中列出的文件之一:


有时我使用:
REQUEST\u URI
而不是
AUTO
“QUERY\u STRING”
作为goDaddy hostings

这就是我使用和工作的地方。 在.htaccess中使用此代码

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php/$0 [PT,L] 
只需确保.htaccess在您的根文件夹中。(即:xampp/htdocs)

然后在config.php(application\config)中替换
config['index\u page']='index.php'

config['index\u page']=''

检查您的httpd.conf文件

改变

AllowOverride None


别忘了更改de配置文件

application/config.php

$config['index_page'] = '';
.htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

您只需在项目文件夹中创建.htaccess文件并写入: 重新启动发动机

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 

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

 And You don't need to define in base_url in config file:
 $config['base_url'] = '';// blank it.

 I hope it will work perfectly ...
RewriteCond%{REQUEST\u FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#将所有其他URL重写为index.php/URL
重写规则^(.*)$index.php?url=$1[PT,L]
ErrorDocument 404 index.php
您不需要在配置文件的base_url中定义:
$config['base_url']=''空白。
我希望它能完美地工作。。。

您遇到了哪些错误?你在使用apache吗?您是否启用了mod_rewrite?您是否阅读了基本文档?是的,我阅读了使用apache的所有文档,并且还启用了mod_rewrite。我应该在不同的htaccess文件中粘贴此代码?它现在将我重定向到本地主机将RewriteBase更改为您的项目设置为的任何路径。此外,这个.htaccess文件应该放在项目的根文件夹中,其中包含“应用程序”和“系统”文件夹是。我的项目在C://wamp/www/mediabox中在mediabox中我有应用程序和系统文件夹,我应该在RewriteBase中写什么?谢谢大家,我已经完成了,我刚刚将RewriteBase替换为我的项目根目录。谢谢。如果我的项目在C://wamp/www/myproject中,我应该为RewriteBase写什么路径?在你的根文件夹中(index.php的sams),这意味着:C://wamp/www/myproject起初对我不起作用。然后我发现你必须在Apaches
httpd.conf
中启用
mod_rewrite
,它才能工作。现在工作得很好,谢谢:)这对我起作用了。我在CentOS 7。我在“”下编辑了我的“/etc/httpd/conf/httpd.conf”文件
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 

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

 And You don't need to define in base_url in config file:
 $config['base_url'] = '';// blank it.

 I hope it will work perfectly ...