去掉php框架CI默认url中的index.php
CI默认的rewrite url中是类似这样的
例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样 http://localhost/CodeIgniter/index.php/welcome。
不太好看,怎么把其中的index.php取掉呢?
解决方法如下:
第一步:
检查 Apache 中 conf/httpd.conf 中是否存在如下一段代码:
#LoadModule rewrite_module modules/mod_rewrite.so
把 LoadModule前边的#去掉。
第二步:
在网站根目录添加.htaccess(和application、system在一个目录下)
内容为:
RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
备注:
1、要注意 /index.php/$1 要根据你目录(Web 目录,比如 http://www.domain.com/index.php)的实际情况来定。
比如网站根目录是 /ci/index.php 则要写成 /ci/index.php/$1
2、RewriteCond $1 !^(index\.php|images|robots\.txt)
上面的代码意思是排除某些目录或文件,使得这些目录不会 rewrite 到 index.php 上,这一般用在图片、js、css 等外部资源上。也就是说非 PHP 代码都要排除出去。(这里我排除了 images 目录和 robots.txt 文件,当然 index.php 也应该被排除)
第三步:
修改application/config.php
查找$config['index_page'] = "index.php";
修改为:$config['index_page'] = "";
第四步:
httpd.conf文件中:
AllowOverride None
改为
AllowOverride All
注意:如果你做了虚拟站点,在httpd-vhosts.conf中做了多站点配置,就像我这样:
<VirtualHost *:81>
DocumentRoot "d:/wamp/www/nxtv"
ServerName 81
<Directory "d:/wamp/www/nxtv">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost> <VirtualHost *:82>
DocumentRoot "d:/wamp/www/codeigniter220"
ServerName localhost:82
<Directory "d:/wamp/www/codeigniter220">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
要记得 把 AllowOverride None 改为 AllowOverride All,我就在这里吃亏了=。=
去掉php框架CI默认url中的index.php的更多相关文章
- 去掉CI框架默认url中的index.php
1:.htaccess //放置在根目录下,和入口文件index.php的同级目录<IfModule mod_rewrite.c>RewriteEngine onRewriteCond % ...
- CI在nginx环境下去掉url中的index.php
在nginx环境下CI框架默认URL规则访问不了,出现500错误,如: http://blog.php230.com/index.php/keywords 今天在服务器配置CI框架环境时,去除URL中 ...
- [中级] 有效删除URL中的index.php
如果你刚接触CI不久又或者刚刚研读CI的使用手册的话,关于如何有效删除URL中index.php以使URL看起来更友好美观的问题,可能是你面对的第一个较为复杂的问题!本贴不是原创,而是一个各种意见的综 ...
- ThinkPHP 隐藏URL中的 index.php
去掉 URL 中的 index.php 通常的URL里面含有index.php,为了达到更好的SEO效果可能需要去掉URL里面的index.php ,通过URL重写的方式可以达到这种效果,通常需要服务 ...
- Elasticsearch——禁止Body中的index覆盖Url中的index参数
本篇继续一下Elasticsearch日常使用的技巧翻译. 在Elasticsearch有很多的api支持在body中指定_index等信息,比如mget或者msearch以及bulk. 默认的情况下 ...
- [tp3.2.1]开启URL(重写模式),省略URL中的index.php
重写模式(省略url中的index.php) 在apache配置文件httpd.conf中,查找 1.mod_rewrite.so, 启动此模块 2.AllowOverride , 值= All 3. ...
- 在nginx下去掉ci框架url中的index.php
ci框架默认的url规则中带有应用的入口文件,例如: example.com/index.php/news/article/my_article 在以上URL中带有入口文件index.PHP,这样的U ...
- 去掉CodeIgniter URL中的index.php
CI默认的rewrite url中是类似这样的,例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样http://localhost /CodeIgniter/index ...
- Thinkphp中取消url中的index.php 和 Home 默认模块
将配置文件中改: <?phpreturn array( //'配置项'=>'配置值' 'URL_MODEL'=>'2', //去掉url中index.php ' ...
随机推荐
- linux 硬盘相关命令学习
summary: 查看硬盘信息:几块硬盘,品牌,容量 查看分区信息 参考资料: Linux下查看磁盘分区命令详解: http://blog.chinaunix.net/uid-26119273-id- ...
- MySql中,复制旧表结构到新表
# 创建学生表 create table student(age int,name varchar(32))engine myisam charset utf8;insert into student ...
- Python 三大神器
Python 三大神器 Python 中有很多优秀的包,本文主要讲一下 pip, virtualenv, fabric 1. pip 用来包管理 文档:https://pip.pypa.io/en/l ...
- 正文字体大小:大 中 小 解决configure: error: Cannot find libmysqlclient under /usr
今天在64位centos5.6系统上编译PHP5.2.17报错 checking for MySQL support... yes, shared checking for specified loc ...
- shadow服务端、客户端配置流程
服务端 系统环境 CentOS 7 64位,由于系统自带python,shadowsocks服务端我们选择python版,过程如下 yum install python-setuptools & ...
- android app widget 创建调用周期
1 ?Android widget 大小问题 2 ?RemoteViewService Android开发历程_15(AppWidget的使用) Appwidget就是手机应用中常常放在桌面(即hom ...
- CentOs7&zookeeper
下载安装包 wget http://www.apache.dataguru.cn/zookeeper/stable/zookeeper-3.4.6.tar.gz 解压 tar xzvf zookeep ...
- c#的协变和逆变
关于协变和逆变要从面向对象继承说起.继承关系是指子类和父类之间的关系:子类从父类继承,所以子类的实例也就是父类的实例.比如说Animal是父类,Dog是从Animal继承的子类:如果一个对象的类型是D ...
- C# 学习之旅(3) --- 会说话的简易计算器
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- HDFS知识体系 思维导图