从codeigniter 2.1.3中删除index.php

时间:2013-03-12 06:33:19

标签: php codeigniter codeigniter-2

在我开这篇文章之前,我确实花了三天时间试图弄清楚这一点,但根本没有运气,所以请帮帮我。感谢~~~~

好的,这是我到目前为止所做的:

  1. 安装CI 2.1.3的新副本,不对任何文件夹进行任何名称更改
  2. 使用我在Google上找到的所有结构创建一个新的.htaccess文件到CI ROOT目录
  3. 将config ['index_page']更改为空,例如。 config ['index_page'] ='';
  4. 设置config ['uri_protocol'] ='REQUEST_URI'或'QUERY_STRING'
  5. 每次我进行上述更改时,甚至重新启动MAMP(PHP 5.4)
  6. 启用:httpd.conf中的LoadModule rewrite_module modules / mod_rewrite.so
  7. 在https.conf中添加'选项索引FollowSymLinks MultiViews'(我唯一不确定的事情)
  8. (我不知道我现在应该尝试什么V_V)
  9. 然后,我得到了这个:

    是的工作:http://ci.dev/index.php/welcome/index

    无效:http://ci.dev/welcome/index

    以下是我现在所拥有的一些细节:

    .htaccess文件:

    # I got 500 error if I uncommend this line: <IfModule mod_rewrite.c>
    #http://ci.dev/index.php/welcome/index  this is works fine only if the above line commend out
    RewriteEngine On
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/?$1 [L]
    # I got 500 error if I uncommend this line: </IfModule> 
    

    的config.php

    $config['index_page'] = '';
    $config['uri_protocol'] = 'QUERY_STRING';
    //$config['uri_protocol'] = 'REQUEST_URI'; 
    

    主机文件

    127.0.0.1 localhost
    127.0.0.1 test.dev
    127.0.0.1 ci.dev 
    

    httpd.conf文件

    #the following line also enabled
    LoadModule rewrite_module modules/mod_rewrite.so  in httpd.conf
    
    ...
    
    # The following code I placed at the bottom of https.conf file
    
    NameVirtualHost *
    
    <VirtualHost *>
     ServerName localhost
     DocumentRoot "/Applications/MAMP/htdocs"
    </VirtualHost>
    
    <VirtualHost *> 
     ServerName ci.dev
     DocumentRoot /Users/coda/Sites/ci
     <Directory /Users/coda/Sites/ci>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>
    </VirtualHost>
    
    <VirtualHost *> 
     ServerName test.dev
     DocumentRoot /Users/coda/Sites/test
    </VirtualHost> 
    

    请帮助我~~~~

    由于

    =============================================== ==================

    感谢所有试图帮助我的人。我终于得到了它的作用,我想在某种程度上我忽略了一些简单的事情之后使事情过于复杂。

    我只是安装另一个CI2副本,只用以下内容更改.htaccess文件:

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

    然后,一切正常〜!!!! -

4 个答案:

答案 0 :(得分:3)

试试这个.htaccess(将它放入项目目录的根目录,即/ chat here):

# To remove index.php from URL

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

如果您在子目录中有项目,请放置RewriteBase,否则将其删除

答案 1 :(得分:1)

将.htaccess文件与index.php文件一起放在应用程序根目录中。 (检查htaccess扩展名是否正确,Bz htaccess.txt对我不起作用。)

并将以下规则添加到.htaccess文件中,

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

然后在application / config / config.php文件中找到以下行

$config['index_page'] = 'index.php';

将变量设置为空,如下所示。

$config['index_page'] = '';

就是这样,它对我有用。

如果它不起作用,请尝试逐个替换以下变量('AUTO','PATH_INFO','QUERY_STRING','REQUEST_URI'和'ORIG_PATH_INFO')

$config['uri_protocol'] = 'AUTO';

答案 2 :(得分:1)

enter image description here

注意:

htdocs 是根文件夹

ci_intro 是代码点火器的文件夹

如果我们有相同的情况,那么你的.htaccess应该是这样的

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ci_intro/

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

注意 RewriteBase / ci_intro / 将ci_info更改为codeigniter的文件夹。

答案 3 :(得分:0)

试一试:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* /codeigniterNameFolder/index.php/$0 [PT,L]

更改codeigniterNameFolder:)