我正在努力删除 CodeIgniter URL 中的“index.php”部分。 我正在使用 CodeIgniter 版本 3.1.2。我已按照有关此问题的其他问题执行所有步骤:
- 将
$config['index_page'] = 'index.php'
更改为$config['index_page'] = ''
- 将
$config['uri_protocol'] = 'AUTO'
更改为$config['uri_protocol'] = 'REQUEST_URI'
- 在我的项目的根文件夹中添加了一个 .htaccess 文件,其中包含以下代码:
RewriteEngine 开启
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
但是,当我尝试访问我的网站时,收到以下错误代码。
Not Found
The requested URL /Toneel/Site/index was not found on this server.
我的 Apache 服务器中的重写模块已打开。 谁能帮我解决这个问题吗?
最佳答案
这个设置对我有用。
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
要允许在 Apache 配置中覆盖 htaccess,您必须编辑 /apache2.conf
文件并将其更改为
AllowOverride All
并重新启动服务器。
关于php - 从 CodeIgniter URL 中删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42455371/