Codeigniter:如何从URL中删除index.php? [英] Codeigniter: how to remove index.php from URL?

查看:60
本文介绍了Codeigniter:如何从URL中删除index.php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了很多文章,并尝试了不同的方法,但是仍然无法使用。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆