404调用不带index.php的控制器时codeigniter 3中出现错误
我正在使用CodeIgniter3 我创建了登录控制器,就像404调用不带index.php的控制器时codeigniter 3中出现错误,php,.htaccess,codeigniter,mod-rewrite,codeigniter-3,Php,.htaccess,Codeigniter,Mod Rewrite,Codeigniter 3,我正在使用CodeIgniter3 我创建了登录控制器,就像 <?php class Login extends CI_Controller { public function index() { echo "It's working"; } } ?> 我还启用了重写模块 它正在工作 http://localhost/codeigniter/index.php/login 但不是在 http://localhost/codeign
<?php
class Login extends CI_Controller
{
public function index()
{
echo "It's working";
}
}
?>
我还启用了重写模块
它正在工作
http://localhost/codeigniter/index.php/login
但不是在
http://localhost/codeigniter/login
我怎样才能解决这个问题。或者它在codeigniter 3.0.4中的错误
请帮忙。换衣服
$config['index_page'] = 'index.php';
到
在config/config.php中打开config.php并执行以下操作
$config['index_page'] = "index.php"
$config['base_url'] = 'http://localhost/your_project/';
$config['index_page'] = '';
到
在某些情况下,uri\u协议
的默认设置不能正常工作。
替换
$config['uri_protocol'] ="AUTO"
借
HTACCESS
您的mod_重写规则正在重定向到/index.php,而不是/codeigniter/index.php 将其放入.htaccess文件中:
RewriteBase /codeigniter/
您可以尝试我在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文件中,并且不允许对这些设置进行覆盖,则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>
ServerName应用程序公司
DocumentRoot“/Users/www/htdocs/application/”
ErrorLog“/Users/www/logs/application\u error.log”
DirectoryIndex.php index.html
命令允许,拒绝
通融
允许从localhost,application.co
要求所有授权
允许超越所有
您使用xampp、wamp的本地主机是什么?在您的config.php上,您是否这样做了$config['index\u page']=''
@wolfgang1983 xampp,在config.php中我有$config['index_page']='index.php'代码>试试这个配置@AldoZumaran得到了未找到的错误对象!在此服务器上找不到请求的URL。如果您手动输入URL,请检查拼写并重试。如果您认为这是服务器错误,请联系网站管理员。错误404 LocalHost感谢我尝试的答案$config['index\u page']=''
但不起作用RewriteRule^(.*)$index.php?/$1[L,QSA]
在htaccess中尝试它,以代替RewriteRule^(.*)$index.php/$1[L]
您在linux中使用服务器吗?是指xampp还是wamp?我使用的是windows 7和xampp,@ZohaibHassan它不工作启用重写\u模块后是否重新启动xampp
?是否替换。htaccess此bcz它为meYa工作过我没有但不工作,这是codeigniter中的错误吗@MayankVadiyaNo不是一只虫子。你的目标是什么url@MayankVadiyaCI3 uri_协议中没有自动
RewriteBase /codeigniter/
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['base_url'] = 'http://localhost/your_project/';
$config['index_page'] = '';
<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>