CodeIgniter 从 url 中删除 index.php [英] CodeIgniter removing index.php from url

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

问题描述

我当前的网址看起来像这样 [mysite]index.php/[rest of the slug].
我想从这些 url 中删除 index.php.

My current urls look like this [mysite]index.php/[rest of the slug].
I want to strip index.php from these urls.

mod_rewrite 在我的 apache2 服务器上启用.在config中,$config['index_page'] = '';

mod_rewrite is enabled on my apache2 server. In config, $config['index_page'] = '';

我的 codeignitor 根 .htaccess 文件包含,

My codeignitor root .htaccess file contains,

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

但是还是不行.我哪里错了?

But still it is not working. Where am I going wrong?

推荐答案

请尝试以下操作

打开 config.php 并进行以下替换

Open config.php and do following replaces

$config['index_page'] = "index.php"

$config['index_page'] = ""

在某些情况下,uri_protocol 的默认设置无法正常工作.只需替换

In some cases the default setting for uri_protocol does not work properly. Just replace

$config['uri_protocol'] ="AUTO"

$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] 

注意:.htaccess 代码因托管服务器而异.在某些托管服务器(例如:Godaddy)中需要使用额外的 ?在上面代码的最后一行.在适用的情况下,以下行将替换为最后一行:

Note: .htaccess code vary depending on hosting server. In some hosting server (e.g.: Godaddy) need to use an extra ? in the last line of above code. The following line will be replaced with last line in applicable case:

// Replace last .htaccess line with this line
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

这篇关于CodeIgniter 从 url 中删除 index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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