本文所写的配置在ThinkPHP3.2.2上测试过。按理也兼容其它版本。

首先修改配置文件:

'URL_CASE_INSENSITIVE'  =>  true,   // 默认false 表示URL区分大小写 true则表示不区分大小写
'URL_MODEL' => 2, // URL访问模式,可选参数0、1、2、3,代表以下四种模式:
// 0 (普通模式); 1 (PATHINFO 模式); 2 (REWRITE 模式); 3 (兼容模式) 默认为PATHINFO 模式

Nginx

推荐:

location / {
try_files $uri $uri/ /index.php?s=$uri&$args;
}

意思是:如果第一个$uri不存在,就访问$uri/;如果$uri/还不存在,访问/index.php?s=$uri&$args。可以后面跟很多个。

try_files
语法: try_files file1 [file2 ... filen] fallback
默认值: 无
作用域: location

再例如:

try_files $uri = 404

什么意思呢?uri不能成功访问,那好,那就给你个404吧。

但是在网上找到的文章大部分是这样配置的:

location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
}

实际上不可行。

Apache

在根目录新建.htaccess文件:

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

IIS环境

如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:

RewriteRule (.*)$ /index\.php\?s=$1 [I]

在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:

<rewrite>
<rules>
<rule name="OrgPage" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}” matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>

附录

Nginx完整配置文件

test.com.conf

server
{
listen 80;
server_name test.com;
index index.php index.html;
root /wwwroot/test.com/; # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
location / {
try_files $uri $uri/ /index.php?s=$uri&$args;
} location ~ \.php
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
} location /status {
stub_status on;
access_log off;
} location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 24h;
} location ~ .*\.(js|css)?$
{
expires 12h;
} if ( $fastcgi_script_name ~ \..*\/.*php ) {
return 403;
} access_log logs/test.com_access.log main;
error_log logs/test.com_error.log notice;
}

ThinkPHP框架里隐藏index.php的更多相关文章

  1. PHP 之 Ci框架下隐藏index.php

    1. 修改 apache 配置文件 开启重写模块 conf/httpd.conf 去掉前面的# LoadModule rewrite_module modules/mod_rewrite.so 对于U ...

  2. ThinkPHP 下如何隐藏index.php

    最近一直在做孕妈团的项目,因为部署到实际项目中出现了链接打不开的情况,要默认添加index.php才能正常访问. 当时忘了是Tinkphp的URL重写模式:以后遇到相同问题,首先要想到URL重写模式. ...

  3. thinkphp的使用——隐藏index.php

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

  4. ThinkPHP框架设计与扩展总结

    详见:http://www.ucai.cn/blogdetail/7028?mid=1&f=5 可在线运行查看效果哦 导言:ThinkPHP框架是国内知名度很高应用很广泛的php框架,我们从一 ...

  5. ThinkPHP CI codeignitor 框架 apache 重写 url 隐藏index.php 服务器 报错:Object not found! 可能是.htaccess隐藏index.php

    隐藏index.php可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则.以Apache为例,需要在入口文件的同级添加.htaccess文件(官方默认自带了该文 ...

  6. ThinkPHP5 隐藏接口里面的index.php

    隐藏index.php 官方介绍是这样的:http://www.kancloud.cn/thinkphp/thinkphp5_quickstart/145250 可以去掉URL地址里面的入口文件ind ...

  7. CI 框架隐藏index.php-ubuntu

    和朋友在做一个小网站,用到了CI框架,之前测试都是在windows上,隐藏index.php也相对比较简单.但服务器是ubuntu系统,需要配置一下,根据网上看到的一些教程,结合自己电脑的特点,记录步 ...

  8. thinkphp中redirect重定向后隐藏index.php

    首先,.htaccess文件要配置好隐藏index.php.系统默认生成的就行. 然后,也是最关键的一部,要在Application/Home/Conf里的config.php文件中增加如下配置: & ...

  9. CI框架 .htaccess 隐藏url在index.php解决方案

    CodeIgniter(下面简称"CI")是一款国外优秀的PHP轻量级MVC框架,它支持PHP4和PHP5.是开发中小型可拓展性需求高的Web应用程序的利器.眼下你所见到的这个博客 ...

随机推荐

  1. hadoop显示ConnectionrRefused

    产生原因重启了服务器 (1)在安装目录/root/cloud/hadoop-2.2.0/ 重新hdfs namenode -format (2) 目录/root/cloud/hadoop-2.2.0/ ...

  2. c#数据库访问读取数据速度测试

    1,使用byte数据读取 2,使用dataset数据读取

  3. python面向对象中的__init__方法怎么理解?

    我们在学习python类的时候,总会碰见书上的类中有__init__()这样一个函数,很多同学百思不得其解,其实它就是python的构造方法. 构造方法类似于类似init()这种初始化方法,来初始化新 ...

  4. 阿里云安装Tomcat

    1.Apache官方网站下载Tomcat http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.0.35/bin/apache-tomcat-8.0 ...

  5. IntelliJ IDEA 发布最新版本13.0.1

    难闻转自:慧都控件网 值得高兴的消息,IntelliJ IDEA v13.0.1目前已经发布,相对于IntelliJ IDEA v13而言,此次更新内容,是略微改进和提高了性能,如代码输入变化,及完善 ...

  6. lockfree

    为什么要lockfree 按我的理解, lockfree就是不去 调用操作系统给定的锁机制. 1. 会有system call,  and system call is expensive; 比如pt ...

  7. C++中的注解理解

    SAL: the Microsoft Source Code Annotation Language. SAL: the Microsoft Source Code Annotation Langua ...

  8. 张洋:浅析PageRank算法

    本文引自http://blog.jobbole.com/23286/ 很早就对Google的PageRank算法很感兴趣,但一直没有深究,只有个轮廓性的概念.前几天趁团队outing的机会,在动车上看 ...

  9. mysql where 1=1和 1=0 的作用

    本文来自网络 where 1=1; 这个条件始终为True,在不定数量查询条件情况下,1=1可以很方便的规范语句. 一.不用where  1=1  在多条件查询中的困扰 举个例子,如果您做查询页面,并 ...

  10. RHEL5.8的NFS配置文件

    RHEL5.8的NFS配置文件 路径:/etc/sysconfig/nfs # # Define which protocol versions mountd # will advertise. Th ...