在我的codeigniter项目中,我使用htaccess从url中删除index.php扩展名。现在,当我尝试调用索引文件夹Eg http://domain.com/project/index/contactus中的函数/页面时,它显示404 Page Not Found Error
。
我的htaccess文件如下所示:
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule \.htaccess - [F]
RewriteRule (.*)(css\/)(.*)$ $2$3 [QSA,L]
RewriteCond %{request_uri} !^index\.php
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
索引控制器:
class Index extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url','timezone_helper'));
$this->load->library('tank_auth');
$this->load->library('session');
timezone();
}
function index()
{
$this->load->view('index/index');
}
function contactus()
{
$data['email']=$this->config->item('webmaster_email', 'tank_auth');
$data['page']='index/contactus';
$this->load->view('layout/template',$data);
}
}
有人可以帮我找到解决这个问题的方法吗?
提前致谢。
答案 0 :(得分:0)
试试这个.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
#RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
我在尝试使用RewriteBase时遇到了问题,所以我不再这样做了(除非我特别需要)。
此外,在 application / config / config.php 中
制作base_url
和index_page
= ''
希望这有帮助!