【问题标题】:My htaccess file keeps bring up 404 errors我的 htaccess 文件不断出现 404 错误
【发布时间】:2014-05-08 19:43:43
【问题描述】:

我不知道这些,我正在努力让这个工作。

我一直收到 404 错误,有人可以帮帮我吗?

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

这是我目前所拥有的。我正在使用 CodeIgniter 框架。

【问题讨论】:

  • Apache 中是否启用了 mod_rewrite?你从哪里得到这个错误?在服务器还是在本地机器上?
  • 我不确定您是否需要第三行。最后一行应该进行重写。尝试注释掉第 3 行。
  • 我已经取出了第三行,但仍然没有乐趣和它的服务器端,我之前在我的主机上使用过这个框架,所以我猜它应该是

标签: php apache .htaccess codeigniter mod-rewrite


【解决方案1】:

你能在 htaccess 文件中试试这个代码吗..

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

这个在我的实例中运行良好...

【讨论】:

  • 我正在使用一个 Godaddy 主机,它告诉我它已启用,但上面仍然没有工作!就像我说的那样,我对此不太了解!
  • 如果您安装在文件夹中而不是根目录中,那么您必须将文件夹名称添加到 RewriteBase。例如:RewriteBase /文件夹名/
  • 我将文件名添加到 / 中,但仍然不高兴!我很困惑
  • 如果您的网站在一个文件夹中,那么您只需添加文件夹名称.. 否则保持原样..
【解决方案2】:

这个适用于我在 goDady 上的网站

<IfModule mod_rewrite.c>

    Options +FollowSymLinks
    RewriteEngine on

    # This one is important for goDaddy
    RewriteBase /


    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    # or you can use like this also 
    RewriteRule ^(.*)$ index.php?url=$1 [L]

</IfModule>

我的文件夹结构是这样的

/
|
 -->mysite
       |
        -->system (d)
       |
        -->application (d)
       |
        -->.htaccess (f)
       |
        -->index.php (f)     

在 config.php

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

在routes.php

$route['default_controller'] = "home"; // whatever default controller

有时 GoDaddy 需要很少的时间来更新 .htaccess,所以请给每次尝试一些时间。并且不要忘记清除浏览器缓存。 Firefox 中的 Ctrl+F5 可在不缓存的情况下刷新。

【讨论】:

  • @Morby-Raybould 您是否尝试过使用默认的 codeIgniter 应用程序文件夹?我的意思是不改变任何东西。您是否从 codeIgniter 或 apache 收到 404 错误?
【解决方案3】:

This post 有一个聪明的答案,可以在您无权访问 RewriteLog(我假设您没有)的服务器上调试 htaccess 中的重写规则。

【讨论】:

    【解决方案4】:

    试试这个代码

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

    【讨论】:

      【解决方案5】:

      试试这个代码,它对我有用。我在我的 windows pc 以及我的 UBUNTU 和 CentOS Server 上的 XAMP、WAMP 中对其进行了测试。我的codeigniter版本是(2.1.0)

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

      【讨论】:

        【解决方案6】:

        使用这个作为你的 .htaccess 文件并检查 mod rewrite 是否启用

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

        【讨论】:

          【解决方案7】:

          试试这个

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

          配置> config.php

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

          【讨论】:

            【解决方案8】:
            try this.
            
            RewriteEngine On   
            RewriteCond %{REQUEST_FILENAME} !-f   
            RewriteCond %{REQUEST_FILENAME} !-d  
            RewriteRule ^(.*)$ index.php?/$1 [L]   
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2014-02-14
              • 2015-10-10
              • 1970-01-01
              • 2015-05-24
              • 1970-01-01
              • 2012-06-22
              • 1970-01-01
              相关资源
              最近更新 更多