【问题标题】:404 error in codeigniter 3 when calling controller without index.php在没有 index.php 的情况下调用控制器时,codeigniter 3 中出现 404 错误
【发布时间】:2016-03-12 07:04:45
【问题描述】:

我正在使用 codeigniter 3。

我创建了类似的登录控制器

<?php
class Login extends CI_Controller
{
     public function index()
     {
          echo "It's working";
     }
}
?>

我的 .htaccess 文件

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

我还启用了重写模块。

正在处理中

http://localhost/codeigniter/index.php/login

但不上

http://localhost/codeigniter/login

我该如何解决这个问题。或其在 codeigniter 3.0.4 中的错误 请帮忙。

【问题讨论】:

  • 你使用什么 localhost,xampp,wamp?
  • 在你的 config.php 上你有没有像这样$config['index_page'] = '';
  • @wolfgang1983 xampp ,在 config.php 我有 $config['index_page'] = 'index.php';
  • 试试这个配置!!! stackoverflow.com/questions/2171185/…
  • @AldoZumaran 收到此错误找不到对象!在此服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。如果您认为这是服务器错误,请联系网站管理员。错误 404 本地主机

标签: php .htaccess codeigniter mod-rewrite codeigniter-3


【解决方案1】:

您的 mod_rewrite 规则正在重定向到 /index.php 而不是 /codeigniter/index.php

把它放在你的 .htaccess 文件中:

RewriteBase /codeigniter/

【讨论】:

    【解决方案2】:

    如果这仍然不起作用,您可能需要检查 httpd conf 以确保允许覆盖 .htaccess,因为 AllowOverride 控制可以放置在 .htaccess 文件中的指令。总是,如果您将设置放在 .htaccess 文件中并且您没有 AllowOverride 这些设置,则默认的 Apache 设置仍将运行,并且您的 .htaccess 中的所有内容都不会被使用。例如

    <VirtualHost *:80> 
      ServerName application.co
    
      DocumentRoot "/Users/www/htdocs/application/"
      ErrorLog "/Users/www/logs/application_error.log"
    
    
    
      <Directory "/Users/www/htdocs/application/" >
          DirectoryIndex index.php index.html
          Order allow,deny
          Allow from all
          Allow from localhost, application.co
          Require all granted
          AllowOverride All
       </Directory>
     </VirtualHost>
    

    【讨论】:

      【解决方案3】:

      改变

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

      $config['index_page'] = '';
      

      在 config/config.php 中

      【讨论】:

      • 感谢您的回答我试过$config['index_page'] = '';但没有工作
      • RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 在 htaccess 中尝试代替 RewriteRule ^(.*)$ index.php/$1 [L]
      • 你在linux中使用服务器吗?是指 xampp 还是 wamp ?
      • 我使用的是 Windows 7 和 xampp,@ZohaibHassan 无法正常工作
      • 启用rewrite_module后是否重启xampp??
      【解决方案4】:

      打开 config.php 并进行以下替换

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

      $config['index_page'] = ""
      

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

      $config['uri_protocol'] ="AUTO"
      

      通过

      $config['uri_protocol'] = "REQUEST_URI"
      

      HTACCESS

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

      【讨论】:

      • 你用这个 bcz 替换 .htaccess 它对我有用
      • 是的,我做了但没有工作,这是 codeigniter 中的错误吗? @MayankVadiya
      • 不,不是错误。你的网址是什么
      • @MayankVadiya CI3 uri_protocol 中没有 AUTO
      【解决方案5】:

      你可以试试我在 xampp 上使用的这个 htaccess。

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

      放在项目的主目录中。

      在 config.php 上

      $config['base_url'] = 'http://localhost/your_project/';
      
      $config['index_page'] = '';
      

      并确保您的类名和文件名的首字母大写,如 here 所述。

      还有更多htaccess Here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-28
        • 2016-10-31
        • 1970-01-01
        • 1970-01-01
        • 2014-03-19
        • 1970-01-01
        • 1970-01-01
        • 2015-11-04
        相关资源
        最近更新 更多