nginx 隱藏index.php 並開啟rewrite日志調試(apache也有)


開啟rewrite 日志

error_log       /data/log/nginx/error.log notice;

位於最外層,大約在文件的前幾行

再在http{}括號里增加一行:rewrite_log on;

重寫的日志將寫入/data/log/nginx/error.log

關鍵代碼

在http{ server{ location {#代碼處} }}里寫代碼

location / {

  if ( !-e $request_filename ) {

    rewrite ^/(.*)$ /index.php?s=$1 last;

    break;

  }

}

若有ask目錄則:

location /ask/ {

  if ( !-e $request_filename ) {

    rewrite ^/(.*)$ /ask/index.php?s=$1 last;

    break;

  }

}

location的順序與執行順序無關

php代碼獲取$_GET['s']代碼

nginx.conf格式

...

events{

}

http{

  upstream xxx{



  }

  server {

    location {

      if () {



        }
    }
  }

}

 apache 的重寫規則 

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index\.php?s=$1 [QSA,PT,L]
#QSA意味着,如果有一個與原始URL查詢字符串傳遞,它將被附加到重寫(olle?p=1將被重寫為index.php?url=olle&p=1。
#L意味着如果規則匹配,不處理任何更多RewriteRules下面這一個。
#PT(pass through to next handler) 傳遞給下一個處理

 


免責聲明!

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



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