Codeigniter:如何从URL中删除index.php? [英] Codeigniter: how to remove index.php from URL?
问题描述
我看了很多文章,并尝试了不同的方法,但是仍然无法使用。
I've looked at many articles and tried different ways but it still doesn't work.
现在我的网址看起来像 mysite.com/index.php/ [controller]
。
目标是 mysite.com/ [controller]
。
Now my URLs look like mysite.com/index.php/[controller]
.
The goal is mysite.com/[controller]
.
在 config.php中:
$config['index_page'] = "";
$config['uri_protocol'] = 'REQUEST_URI';
我的 .htaccess 文件包含
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
还在我的Apache服务器中启用了 mod_rewrite 。
Also mod_rewrite is enabled in my Apache server.
还有其他解决方案吗?
Any other solutions?
推荐答案
在 application / config / config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
在 .htaccess
中(放置在应用程序外部文件夹中)
in .htaccess
(Place Outside application folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
更新2018-02-27
$config['base_url'] = 'https://stackoverflow.com/'; # Must fill
否则您会收到此错误 Codeigniter回显[:: 1]而不是localhost
else you get this error Codeigniter echoing [::1] instead of localhost
使用此 .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
这篇关于Codeigniter:如何从URL中删除index.php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!