我使用codeigniter开发一个简单的php项目。我的htaccess看起来像这样
RewriteEngine on
RewriteCond $1 !^(index'.php|images|css|js|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
我的基本网址是
$config['base_url'] = 'http://localhost/Achalaweerasooriya.github.io';
我的索引页是
$config['index_page'] ="";
我的主要控制器类是登录控制器。
当我运行项目时,它调用登录控制器,网址是
http://localhost/Achalaweerasooriya.github.io/index.php
这将显示登录表单。当我输入登录详细信息并单击登录时,它应该验证用户。我为登录按钮提供的 href 是
href="<?php echo base_url('');?>LoginController/validate"
然后网址显示为
"http://localhost/Achalaweerasooriya.github.io/LoginController/validate"
这在逻辑上是正确的。
但是当我使用正确的用户名和密码单击登录按钮时,会生成404错误,说找不到对象错误说"找不到对象!
在此服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写,然后重试。
如果您认为这是服务器错误,请与网站站长联系。
错误 404
本地主机Apache/2.4.17 (Win32( OpenSSL/1.0.2d PHP/5.5.30">
但是如果我手动将索引.php添加到 URL(然后 URL 看起来像"http://localhost/Achalaweerasooriya.github.io/index.php/LoginController/validate"(,则会显示正确的页面。作为解决方案,我将index.php添加到基本网址,使其看起来像
$config['base_url'] = 'http://localhost/Achalaweerasooriya.github.io/index.php';
但是当我使用 base_url((; 调用来链接外部 css 和 javascript 时,它们停止了应有的响应。
请指出我正确的方向。提前谢谢。
如果你的.htaccess文件可以工作,那么删除与index相关的旧代码行.php并添加下面的代码
或者只是将.htaccess设置为空白并尝试以下代码。它对我有用。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [QSA,L]
</IfModule>
从 $config['base_url'] 中删除索引.php并尝试此操作
http://addictors.in/remove-index-php-from-url-in-codeigniter/
并重新启动服务器