去掉 URL 中的 index.php

通常的URL里面含有index.php,为了达到更好的SEO效果可能需要去掉URL里面的index.php ,通过URL重写的方式可以达到这种效果,通常需要服务器开启URL_REWRITE模块才能支持。  

例如原来的 URL 为:

http://127.0.0.1/index.php/Index/insert

去掉 index.php 之后变为:  

http://127.0.0.1/Index/insert

第一步:更改Apache的httpd.conf  配置文件

1、确认加载了mod_rewrite.so 模块(将如下配置前的 # 号去掉)

LoadModule rewrite_module modules/mod_rewrite.so

2、AllowOverride none  改   AllowOverride ALL

保存httpd.conf,重启Apache服务器;

第二、添加 .htaccess 文件 Rewrite 规则

  如果是Apache则需要在入口文件的同级添加.htaccess文件,内容如下:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$ [QSA,PT,L]
</IfModule>

第三步、更改项目配置文件

  编辑项目配置文件 Conf/config.php ,将 URL 模式配置为 2(Rewrite模式):  

'URL_MODEL'=>,

至此,各个配置已经完成。保存各配置文件后,重启 Apache 服务器。

内容参考:

http://www.5idev.com/p-thinkphp_htaccess_rewrite.shtml

http://jingyan.baidu.com/article/6079ad0e86ec9928ff86dbe0.html?st=2&os=0&bd_page_type=1&net_type=2

ThinkPHP 隐藏URL中的 index.php的更多相关文章

  1. ThinkPHP路由去掉隐藏URL中的index.php

    官方默认的.htaccess文件 <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On ...

  2. ThinkPHP 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php

    1.首先修改Apache的httpd.conf文件. 确认httpd.conf配置文件中加载了mod_rewrite.so 模块,加载的方法是去掉mod_rewrite.so前面的注释#号 讲http ...

  3. ThinkPHP去掉URL中的index.php

    我的环境是apache+ubuntu 1,先确认你有没mod_rewrite.so模块 /usr/lib/apache2/modules/mod_rewrite.so 然后在httpd.conf最后一 ...

  4. ThinkPHP去除url中的index.php

    例如你的原路径是 http:.httpd.conf配置文件中加载了mod_rewrite.so模块  .AllowOverride None 讲None改为 All      .确保URL_MODEL ...

  5. ThinkPHP -- 去除URL中的index.php

    原路径是 http://localhost/test/index.php/index/add 想获得的地址是 http://localhost/test/index/add 那么如何去掉index.p ...

  6. ThinkPHP5 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php

    1.首先修改Apache的httpd.conf文件. 确认httpd.conf配置文件中加载了mod_rewrite.so 模块,加载的方法是去掉mod_rewrite.so前面的注释#号 讲http ...

  7. TP5隐藏url中的index.php

    在public文件夹下,有个.htacess文件,没有则新建一个, 如果已有这个文件,原文件内容如下: <IfModule mod_rewrite.c> Options +FollowSy ...

  8. thinkPHP隐藏url地址栏中的index.php方法

    http://localhost/workSpace/First/index.php/Home/Index/index隐藏上面url中的index.php方法如下: 第一步.删除apache配置文件( ...

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

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

随机推荐

  1. 自动将指定目录下面的文件转换为UTF-8

    using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...

  2. html 概念

    HTML 超文本标记语言,标准通用标记语言下的一个应用.http://baike.baidu.com/link?url=RYF4Pj7VUPifcXatU7OJLGRljIgkp4MjzkspARor ...

  3. OutPut子句的使用限制

    Output子句很方便,多数情况下可以省略了更新后插入或者删除后插入操作表,将2个语句变成1个语句操作.不管从语句美观还是效率上都是有不错的提升, 但是对于Output自身,也是有一些限制的. 从文档 ...

  4. Linux之od命令详解

    功能说明:输出文件内容.语 法:od [-abcdfhilovx][-A <字码基数>][-j <字符数目>][-N <字符数目>][-s <字符串字符数&g ...

  5. node.js express 4.x 安装指南

    前几天express 推出了4.0,得知这个消息,自己尝试了一下,突然发现用以前的文档上的操作出现了各种问题.结果只能去看文档,现在在这个给大家分享下4.0版本的安装. 先说下如果需要用express ...

  6. Junit mockito 测试Controller层方法有Pageable异常

    1.问题 在使用MockMVC+Mockito模拟Service层返回的时候,当我们在Controller层中参数方法调用有Pageable对象的时候,我们会发现,我们没办法生成一个Pageable的 ...

  7. [LeetCode] Serialize and Deserialize Binary Tree 二叉树的序列化和去序列化

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  8. [LeetCode] Best Time to Buy and Sell Stock III 买股票的最佳时间之三

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  9. [LeetCode] Implement strStr() 实现strStr()函数

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  10. [LeetCode] Reverse Integer 翻转整数

    Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to ...