在我的codeigniter项目中,我正在使用htaccess从url中删除index.php扩展。现在,当我尝试调用索引文件夹中的函数/页面时,例如:http://domain.com/project/index/contactus,它显示404 Page Not Found Error
。
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);
}
}
谁能帮我找到解决这个问题的方法?为你的.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
变为= ''
希望这对你有帮助!