简体   繁体   English

调用没有index.php的控制器时,codeigniter 3中出现404错误

[英]404 error in codeigniter 3 when calling controller without index.php

I am using codeigniter 3. 我正在使用codeigniter 3。

I created login controller like 我创建了类似的登录控制器

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

My .htaccess file 我的.htaccess文件

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

I also enabled rewrite module. 我还启用了重写模块。

It is working on 它正在

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

but not on 但不在

http://localhost/codeigniter/login

How can I solve this issue. 我该如何解决这个问题。 or its bug in codeigniter 3.0.4 Please help. 或它在Codeigniter 3.0.4中的错误,请提供帮助。

Your mod_rewrite rules are redirecting to /index.php instead of /codeigniter/index.php . 您的mod_rewrite规则将重定向到/index.php而不是/codeigniter/index.php

Put this in your .htaccess file: 将其放在您的.htaccess文件中:

RewriteBase /codeigniter/

change 更改

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

to

$config['index_page'] = '';

in config/config.php 在config / config.php中

Open config.php and do following replaces 打开config.php并执行以下替换

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

to

$config['index_page'] = ""

In some cases the default setting for uri_protocol does not work properly. 在某些情况下, uri_protocol的默认设置无法正常工作。 Just replace 只需更换

$config['uri_protocol'] ="AUTO"

by 通过

$config['uri_protocol'] = "REQUEST_URI"

HTACCESS .htaccess的

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

You can try this htaccess i use on xampp. 您可以尝试我在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]

Place in main directory of project. 放置在项目的主目录中。

And on config.php 并在config.php上

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

$config['index_page'] = '';

And make sure your class and file names have first letter upper case as explained here . 并确保你的类和文件名具有作为解释的第一个字母大写这里

Also for more htaccess Here 也更多的htaccess 在这里

if this is still not working, you might want to check you httpd conf to make sure Override for .htaccess is allowed because AllowOverride controls what directives may be placed in .htaccess files. 如果仍然无法使用,则可能需要检查httpd conf,以确保允许覆盖.htaccess,因为AllowOverride控制可以在.htaccess文件中放置哪些指令。 Invariably, if you place settings in the .htaccess file and you do not AllowOverride for those settings, the dafault Apache settings would still run and everything in your .htaccess would not be used. 始终,如果将设置放置在.htaccess文件中,并且没有为这些设置设置AllowOverride,则dafault Apache设置仍将运行,并且.htaccess中的所有内容均不会使用。 For example 例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM