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;
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM