Nginx环境下隐藏index.php

Nginx环境

在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf中配置转发规则实现:

  1. location / { // …..省略部分代码 
  2.   if (!-e $request_filename) { 
  3.     rewrite  ^(.*)$  /index.php?s=$1  last; 
  4.     break; 
  5.   } 

其实内部是转发到了ThinkPHP提供的兼容模式的URL,利用这种方式,可以解决其他不支持PATHINFO的WEB服务器环境.

如果你的ThinkPHP安装在二级目录,Nginx的伪静态方法设置如下,其中youdomain是所在的目录名称.

  1. location /youdomain/ { 
  2. if (!-e $request_filename){ 
  3.     rewrite  ^/youdomain/(.*)$  /youdomain/index.php?s=$1  last; 
  4.   } 
  5. }

举个例子

  1. location /tp/public/ {
    index index.html index.htm index.php l.php;
    autoindex off;
    if (!-e $request_filename) {
    rewrite ^/tp/public/(.*)$ /tp/public/index.php?s=/$1 last;
    break;
    }
posted @ 2019-06-05 10:03  你的老张  阅读(4516)  评论(0编辑  收藏  举报