【问题标题】:.htacces is not working with CodeIgniter 1.7.3, php 5.3.htaccess 不适用于 CodeIgniter 1.7.3、php 5.3
【发布时间】:2012-09-07 08:57:43
【问题描述】:

我尝试使用 .htaccess、CI 1.7.3 和 php 5.3 隐藏 index.php 并收到错误 404。 但它在我的开发服务器上运行良好,它有 php 5.2,其余的都是相同的配置,我用 HMVC 开发了我的应用程序,我的 .htaccess 是

    RewriteEngine on
    Options -Indexes
    RewriteBase /myapp/

    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /myapp/index.php?/$1 [L] 

有人建议我如何解决这个问题,我应该升级我的 CI 版本吗?

谢谢

【问题讨论】:

    标签: php .htaccess codeigniter


    【解决方案1】:

    试试

    RewriteEngine on
    Options -Indexes
    RewriteBase /myapp/
    
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [L] 
    

    或者

    RewriteEngine on
    Options -Indexes
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ myapp/index.php?/$1 [L] 
    

    可能是您的 .htaccess 认为它​​应该打开 myapp/myapp/index.php

    【讨论】:

      【解决方案2】:

      从 system/application/config 目录打开 config.php

      替换

      $config['index_page'] = “index.php” by $config['index_page'] = “”
      

      在CodeIgniter目录的根目录下创建一个“.htaccess”文件

      并添加以下行。

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

      在某些情况下,uri_protocol 的默认设置无法正常工作。

      要解决这个问题,只需更换

      `$config['uri_protocol'] = “AUTO”` 
      

      通过

       $config['uri_protocol'] = “REQUEST_URI” 
      

      来自系统/应用程序/config/config.php

      【讨论】:

        【解决方案3】:

        您是否检查过您的 apache 重写模块是否包含在您的服务器中,并在 apache 配置文件中启用了重写规则。

        【讨论】:

        • 它已在我的 .htaccess 文件中启用,但无法正常工作
        • 请检查您的服务器,了解您的 .htaccess 文件中没有的重写模块
        猜你喜欢
        • 1970-01-01
        • 2012-07-15
        • 2018-05-16
        • 1970-01-01
        • 1970-01-01
        • 2018-01-11
        • 2017-01-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多