《PHP教程:thinkphp在低版本Nginx 下支持PATHINFO的方法分享》要點:
本文介紹了PHP教程:thinkphp在低版本Nginx 下支持PATHINFO的方法分享,希望對您有用。如果有疑問,可以聯系我們。
相關主題:thinkphp教程
PHP教程最近在用thinkphp做一個項目,基本完成后部署到nginx服務器上才發覺nginx是不支持pathinfo的那么我們如何來處理呢.
PHP教程Nginx環境
PHP教程在Nginx低版本中,是不支持PATHINFO的,但是可以通過在Nginx.conf(在/usr/local/nginx/conf/nginx.conf或者通過find / | grep nginx.conf來查找位置)中配置轉發規則實現:在nginx配置文件中添加:
PHP教程
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
PHP教程其實內部是轉發到了ThinkPHP提供的兼容模式的URL,利用這種方式,可以解決其他不支持PATHINFO的WEB服務器環境.
如果你的ThinkPHP安裝在二級目錄,Nginx的偽靜態方法設置如下,其中youdomain是所在的目錄名稱.
PHP教程
location /youdomain/ {
if (!-e $request_filename){
rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last;
}
}
PHP教程如:
PHP教程
location /thinkphp/ {
if (!-e $request_filename){
rewrite ^/thinkphp/(.*)$ /thinkphp/index.php?s=$1 last;
}
}
PHP教程語法:rewrite regex replacement flag? (last???? 相當于apache里面的[L]標記,表示rewrite.)
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/6313.html