此应用程序在 Codeigniter 版本 = 3.1.3 中构建。在构建此应用程序时,可以使用此 htaccess 文件正常工作,但今天当我运行此应用程序并遇到此类错误时。
When run my codeigniter website, htaccess file can't rewrite my index.php url. so, requested URL was not found error shown.
正常工作的网址 => localhost/Magpie/index.php/Front_master/aboutus.html
错误网址 => localhost/Magpie/index.php/Front_master/aboutus.html
这是我的 htaccess 代码:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /Magpie/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Controller 文件:Front_master.php
<?php
class Front_master extends CI_Controller {
public $result = array();
public function __construct() {
parent::__construct();
//load models
$this->result["getContact"] = $this->GetInformation->getContact();
$this->result["getLogo"] = $this->GetInformation->getLogo();
$this->result["getSlide"] = $this->GetInformation->getSlide();
$this->result["getServices"] = $this->GetInformation->getServices();
$this->result["getContent"] = $this->GetInformation->getContent();
$this->result["getPropertyListing"] = $this->GetInformation->getPropertyListing();
$this->result["getBestDeal"] = $this->GetInformation->getBestDeal();
$this->result["getTeam"] = $this->GetInformation->getTeam();
}
public function index() {
$data = array();
$data['title'] = 'Home Page';
$data['header'] = $this->load->view('frontview/header', $this->result, TRUE);
$data['slider'] = $this->load->view('frontview/slider', $this->result, TRUE);
$data['dashboard'] = $this->load->view('frontview/dashboard', $this->result, TRUE);
$data['footer'] = $this->load->view('frontview/footer', '', TRUE);
$this->load->view('frontview/master', $data);
}
public function aboutus() {
$data = array();
$data['title'] = 'About Us';
$data['header'] = $this->load->view('frontview/header', $this->result, TRUE);
$data['dashboard'] = $this->load->view('frontview/about_us', $this->result, TRUE);
$data['footer'] = $this->load->view('frontview/footer', $this->result, TRUE);
$this->load->view('frontview/master', $data);
}
}
最佳答案
使用这个 htaccess 代码
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /Magpie/
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
第 2 步:
删除 codeigniter 配置中的 index.php
$config['index_page'] = '';
第 3 步:
允许在 Apache 配置(命令)中覆盖 htaccess
sudo nano /etc/apache2/apache2.conf
并编辑文件并更改为
AllowOverride All
对于 www 文件夹
第 4 步:
启用 apache mod rewrite(命令)
sudo a2enmod rewrite
第 5 步:
重启 Apache(命令)
sudo /etc/init.d/apache2 restart
并使用此网址:
localhost/Magpie/Front_master/aboutus
关于.htaccess - Codeigniter htaccess 在 ubuntu 16.04 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51172424/