我知道有很多这样的问题,但我应用了所有内容,但我找不到正确的方法。
.htaccess是:
RewriteEngine On
RewriteBase /NewWebsite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /NewWebsite/error.php
</IfModule>
在config / config.php中:
$config['base_url'] = 'https://mydomain.com/NewWebsite/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; // I change it with REQUEST_URI and PATH_INFO but it don't work
在服务器中,启用了mod_rewrite。
在localhost中,一切正常但是当我将其上传到服务器时,只有索引工作(你看到的第一页)但是当我想在网上“移动”时,我有404错误,找不到页面。
我将展示一个控制器以及我如何调用它来更改为另一个视图。
class Products_controller extends CI_Controller {
public function index()
{
$this->load->helper('url');
$this->load->helper('html');
$this->load->view('products.php');
}
}
从索引来看,我称之为:
echo base_url('Products_controller/index');
OR
echo base_url('Products'); // I have in config/routes.php ---> $route['Products'] = "Products_controller/index";
任何人都可以帮助我吗?我错过了什么?
感谢。
答案 0 :(得分:0)
虽然.htaccess有时依赖托管服务器,但您可以尝试使用此功能并告诉我们。用以下代码替换.htaccess代码:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
多数民众赞成。
答案 1 :(得分:0)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /NewWebsite/index.php [L]
</IfModule>
以上操作应该有效 - 确保您的.htaccess
位于您要运行的子目录中。
还要确保基本目录中没有冲突的.htaccess
规则。
答案 2 :(得分:0)
最后,我得到了一个关于这个主题的解决方案。它不是关于.htaccess问题,是一个真正的转储和简单的错误。
在CodeIgniter中,控制器的名称和文件的名称 必须具有完全相同的名称。我一直在定义我的 第一个字母大写但不在文件中的控制器 名称。现在一切都好!
谢谢你们。