【问题标题】:CodeIgniter - removing index.phpCodeIgniter - 删除 index.php
【发布时间】:2011-07-09 09:11:11
【问题描述】:

在我的 CI 安装中删除 index.php 时遇到了一些问题,我当前使用的 .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>
ErrorDocument 404 /index.php
</IfModule> 

我的 CI 安装从 public_html 目录返回,我已将配置更改为

$config['index_page'] = "";

所以我的 CI 如下所示

/core-1.7.3
/public_html/index.php

当我输入 url 时,我得到 404,但是当我将 index.php 放在它前面时,它可以正常工作:S

我很困惑

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    嗨 我已经安装了那个 1.7.3 并且这个 .htaccess 与这个 URL 一起工作-

    /CodeIgniter_1.7.3/public_html/welcome
    

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

      仔细阅读 Avisek Chakraborty 的评论并确保您已完成所有操作,但是 在我看来,您没有正确安装 mod_rewrite。 通过使用以下测试确保它是: http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html

      它是为 Windows 编写的,但你应该明白。

      如果不起作用,请安装 mod_rewrite 并重试。

      【讨论】:

        【解决方案3】:

        也尝试改变这个:

        $config['uri_protocol'] = “REQUEST_URI” 
        

        【讨论】:

        • 现在它只为每个页面提供 404。
        • 你能检查这些东西吗- 1. 如果你的安装不在服务器根目录中,你需要将 RewriteBase 行从“RewriteBase /”修改为“RewriteBase /folder/” 2.确保你的apache 使用 mod_rewrite 模块 3. 确保将 apache 配置为接受所需的 .htaccess 指令 [reference-codeigniter.com/wiki/mod_rewrite/]
        【解决方案4】:

        你需要 FollowSymLinks 指令来重写 .htaccess ...

        Options Indexes FollowSymLinks
        
           <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php/$1 [L]
           </IfModule>
        

        Options 指令位于The Apache Docs

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-07-26
          • 2012-10-30
          • 2019-04-06
          • 2019-08-03
          • 2017-04-04
          • 2014-09-20
          • 2011-08-10
          • 2016-05-13
          相关资源
          最近更新 更多