Home  >  Article  >  php教程  >  如何去除codeIgniter开发的网站url里面的index.php字符串

如何去除codeIgniter开发的网站url里面的index.php字符串

WBOY
WBOYOriginal
2016-06-13 09:36:49777browse

使用codeIgniter(简称CI)做网站的朋友应该都会发现网站的任何url默认都会带个index.php,这个从SEO的角度上来说,对网站的影响是不大的,但是url的美观上来说,这个是非常让人不舒服的,下面我们就来看看如何去除使用codeIgniter开发的网站的url里面的index.php这几个字符吧。

做以下操作之前请确定你网站所运行的环境支持使用 .htaccess 进行url重写,如果可以的话,请继续往下看:

在网站根目录新建一个 .htaccess 文件,输入如下内容:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\\.php|images|css|js|robots\\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

上面的代码第四行的意思是排除某些目录或文件,使得这些目录不会 rewrite 到 index.php 上,这一般用在图片、js、css 等外部资源上。也就是说非 PHP 代码都要排除出去。(这里我排除了 images 目录 css 目录 js 目录 以及 robots.txt 文件,当然 index.php 也应该被排除)

然后找到application/config/config.php文件,将:

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

改为

$config['index_page'] = "";

您可能感兴趣的文章

  • 如何去除dedeCMS后台登陆页面的广告
  • thinkphp 如何去除url中的index.php
  • 如何优化网站页面提高网页的加载速度
  • JavaScript去除字符串空格方法完美总结
  • thinkphp截取中文字符串的方法
  • 肩,背部肌群锻炼-引体向上-俯立划船-俯卧挺身-站姿负重俯身弯起-坐姿颈后下拉-俯立正握上拉-颈前宽握引体向上
  • php bom去除工具,php批量去除bom的代码
  • Mysql查询带单引号字符串及插入带单引号字符串需要注意问题
Statement:
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