删除codeigniter 2.1.0中的index.php

时间:2012-03-12 12:43:56

标签: php codeigniter

我在google上尝试了一些与在codeigniter中删除index.php相关的内容,但没有解决方案适用于我 我使用的是codeigniter 2.1.0版 如何从我的URL中删除索引?

由于

9 个答案:

答案 0 :(得分:22)

application/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> 

你们都准备好了!

答案 1 :(得分:5)

对我来说,Raphael Caixetas的解决方案无效,但确实如此:

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

答案 2 :(得分:1)

您是否尝试过使用CodeIgniter用户指南中提供的示例?

  

默认情况下,index.php文件将包含在您的网址中:

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请求,   images和robots.txt被视为对index.php的请求   文件。

http://codeigniter.com/user_guide/general/urls.html

答案 3 :(得分:1)

我在许多不同的主机上在apache2上测试了这个并且效果很好。

使用此htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

请确保enabled mod_rewirte phpinfo();

然后在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_URI代替AUTO"QUERY_STRING"用于goDaddy托管

答案 4 :(得分:1)

检查你的httpd.conf文件

更改

AllowOverride None

AllowOverride All

答案 5 :(得分:0)

除了Robert Stanley提供的.htaccess文件(请参阅他的回答)之外,请转到application/config/config.php,查找$config['index_page'] = "index.php";并将其替换为$config['index_page'] = "";

答案 6 :(得分:0)

这是我使用和工作的。 在.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_page']='index.php'   至 config['index_page']=''

答案 7 :(得分:0)

不要忘记更改配置文件!

<强>应用/ config.php中

$config['index_page'] = '';

.htaccess

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

答案 8 :(得分:0)

您只需要在项目文件夹中创建.htaccess文件并编写:         RewriteEngine On

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 ...