ci框架默认的url规则中带有应用的入口文件,例如:

example.com/index.php/news/article/my_article

在以上URL中带有入口文件index.PHP,这样的URL规则对搜索引擎来说是不友好的,那么如何去除这个index.php呢?
apache环境下:
通过 .htaccess 文件来设置一些简单的规则删除它。下面是一个例子,使用“negative”方法将非指定内容进行重定向:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

如果你的项目不在根目录请把上面这一句改为:

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

在上面的例子中,可以实现任何非 index.php、images 和 robots.txt 的 HTTP 请求都被指向 index.php。

Nginx环境下:
修改nginx配置文件,在SERVER段中添加如下代码:

location /{

    index index.php index.hml index.htm
if (-f $request_filename/index.php) {
rewrite (.*) $1/index.php
break;
}
if (!-e $request_filename) {
rewrite (.*) /index.php;
}
}

在nginx下去掉ci框架url中的index.php的更多相关文章

  1. 去掉php框架CI默认url中的index.php

    CI默认的rewrite url中是类似这样的 例如你的CI根目录是在/CodeIgniter/下,你的下面的二级url就类似这样 http://localhost/CodeIgniter/index ...

  2. CentOS 下用的是lnmp 的包配置Nginx 下的CI伪静态(搞爽了)

    server { listen ; server_name cy.com; index index.html index.htm index.php default.html default.htm ...

  3. CI在nginx环境下去掉url中的index.php

    在nginx环境下CI框架默认URL规则访问不了,出现500错误,如: http://blog.php230.com/index.php/keywords 今天在服务器配置CI框架环境时,去除URL中 ...

  4. (转)nginx下基于ThinkPHP框架的网站url重写

    nginx下基于ThinkPHP框架的网站url重写nginx下的基于thinkphp的应用的url重写,需了解thinkphp的各种url格式参数的处理逻辑以及nginx重写的原理.简单点说,无论哪 ...

  5. CI框架 -- URL

    移除 URL 中的 index.php 默认情况,你的 URL 中会包含 index.php 文件: example.com/index.php/news/article/my_article 如果你 ...

  6. [中级] 有效删除URL中的index.php

    如果你刚接触CI不久又或者刚刚研读CI的使用手册的话,关于如何有效删除URL中index.php以使URL看起来更友好美观的问题,可能是你面对的第一个较为复杂的问题!本贴不是原创,而是一个各种意见的综 ...

  7. ThinkPHP 隐藏URL中的 index.php

    去掉 URL 中的 index.php 通常的URL里面含有index.php,为了达到更好的SEO效果可能需要去掉URL里面的index.php ,通过URL重写的方式可以达到这种效果,通常需要服务 ...

  8. Elasticsearch——禁止Body中的index覆盖Url中的index参数

    本篇继续一下Elasticsearch日常使用的技巧翻译. 在Elasticsearch有很多的api支持在body中指定_index等信息,比如mget或者msearch以及bulk. 默认的情况下 ...

  9. [tp3.2.1]开启URL(重写模式),省略URL中的index.php

    重写模式(省略url中的index.php) 在apache配置文件httpd.conf中,查找 1.mod_rewrite.so, 启动此模块 2.AllowOverride , 值= All 3. ...

随机推荐

  1. [编辑] 分享一些java视频

    1.官网:http://www.atguigu.com/,导航栏视频下载,根据自己的需求下载,对应的视频,其次可以下载相应的文档. 2.百度网盘: 链接: http://pan.baidu.com/s ...

  2. Appium-android环境的快速搭建

    1.Android的要求: Android的sdk api>=16 appium支持android在linux,osx(mac),window平台 2.Appium的安装与启动: 安装: (1) ...

  3. springday05-go1

    新建web工程spring-netcross1.导入spring文件夹里的七个jar包,另外还要导入jdbc-lib的四个jar包,ojdbc.jar,commoms-pool,commons-dbc ...

  4. unable to connect to the virtual device Genymotion 神器启动问题

    截图: 解决方法:win7以上用户在桌面找到:网络--右键(属性)--更改适配器设置--VirtualBox Host-Only Network--属性--双击:Internet 协议版本4(TCP/ ...

  5. 将Excel导入数据库

    在Control 中: public ActionResult ImportExcel() { return View(); } //客户导入 [HttpPost] public ActionResu ...

  6. 解决vim无法返回上次的位置

    就是在vim的配置文件 ~/.vimrc 中添加一行这个: au BufReadPost * |if line("'\"") <= line("$&quo ...

  7. Mysql 经典

  8. android提示框

    // 对话框 AlertDialog.Builder builder = new Builder(MainActivity.this); builder.setMessage("是否确认删除 ...

  9. JSP01

    <%@page pageEncoding="UTF-8"    //page:设置此文件的编码 contentType="text/html;charset=utf ...

  10. SendKeys:基本使用

    使用SendKeys将键击和组合键击发送到活动应用程序.此类无法实例化.若要发送一个键击给某个类并立即继续程序流,请使用Send.若要等待键击启动的任何进程,请使用SendWait. 每个键都由一个或 ...