在TP5.0中查閱tp5官方文檔,注意:5.0取消了URL模式的概念,並且普通模式的URL訪問不再支持。
phthinfo 是什么?
PHP中的全局變量$_SERVER['PATH_INFO']是一個很有用的參數,眾多的CMS系統在美化自己的URL的時候,都用到了這個參數。
對於下面這個網址:
http://www.test.com/index.php/foo/bar.html?c=index&m=search
我們可以得到 $_SERVER['PATH_INFO'] = ‘/foo/bar.html’,而此時 $_SERVER['QUERY_STRING'] = 'c=index&m=search';
通常,我們最初開始PHP程序編寫的時候,都會使用諸如: http://www.test.com/index.php?c=search&m=main 這樣的URL,這種URL不僅看起來非常奇怪,而且對於搜索引擎也是非常不友好的。
很多搜索引擎收錄的時候,都會忽略Query String之后的內容,google雖然不會忽略Query String,但是對於其他不含Query String的頁面,會給於比較高的PR值。
tp5默認不支持自動轉換生成?s=/xxxx這種形式的url,關於Nginx的path_info可以參考以下方法:
server {
listen 80;
root /var/www/html/health_data;
index index.html index.htm index.php;
server_name uuu.xxx.com;
location / {
try_files $uri $uri/ =404;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
location ~ .+\.php($|/) {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param PATH_INFO $fastcgi_path_info; #加上這一句就可以跑了
include snippets/fastcgi-php.conf;
}
}