CI除去URL中的INDEX.PHP

WBOY
Release: 2016-06-13 12:02:35
Original
875 people have browsed it

CI去掉URL中的INDEX.PHP

CI默认的rewrite url中是类似这样的,http://localhost:9090/ci/index.php/news;

这样写出的URL不太好看,并且也不友好,如何去掉这个INDEX.PHP呢?

1、首先先确定服务器用的是AP还是IIS,这里介绍AP的处理方法;

检查AP是否支持mod_rewrite,如果不支持,请打开HTTPD.CONF配置文件

找到下面这句话

LoadModule rewrite_module modules/mod_rewrite.so ,把该行前的#去掉;

搜索 ALLOWOVERRIDE NONE修改为ALL

2、在CI主目录的同级下,新建一个文本文档输入以下内容然后另存为.htaccess

?

RewriteEngine on ??

RewriteCond $1 !^(index\.php|images|robots\.txt) ??

RewriteRule ^(.*)$ /ci/index.php/$1 [L]

?

以上代码的意思是排除某些目录或文件,使用这些上当不会rewrite到index.php上,一般用在静态资源上;

也就是说非PHP代码都要做排除;

注意:/ci/index.php/$1 此处要根据你目录实际情况而定比如你的运行目录为PL那么主把CI改成PL

?

3、修改CI的配置文件 CONFIG.PHP

找到$config['index_page']="index.php"改为$config["index_page"]="";

完成后重启AP 看下效果

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template