[英]404 error in codeigniter 3 when calling controller without index.php
我正在使用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中的错误,请提供帮助。
您的mod_rewrite规则将重定向到/index.php而不是/codeigniter/index.php 。
将其放在您的.htaccess文件中:
RewriteBase /codeigniter/
更改
$config['index_page'] = 'index.php';
至
$config['index_page'] = '';
在config / config.php中
打开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]
您可以尝试我在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'] = '';
并确保你的类和文件名具有作为解释的第一个字母大写这里 。
也更多的htaccess 在这里
如果仍然无法使用,则可能需要检查httpd conf,以确保允许覆盖.htaccess,因为AllowOverride控制可以在.htaccess文件中放置哪些指令。 始终,如果将设置放置在.htaccess文件中,并且没有为这些设置设置AllowOverride,则dafault 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.