詳解 $_SERVER 函數中QUERY_STRING和REQUEST_URI區別

詳解 $_SERVER 函數中QUERY_STRING和REQUEST_URI區別

 
實例:

1,http://localhost/aaa/ (打開aaa中的index.php)
結果:
$_SERVER['QUERY_STRING'] = "";
$_SERVER['REQUEST_URI']  = "/aaa/";
$_SERVER['SCRIPT_NAME']  = "/aaa/index.php";
$_SERVER['PHP_SELF']     = "/aaa/index.php";

2,http://localhost/aaa/?p=222 (附帶查詢)
結果:
$_SERVER['QUERY_STRING'] = "p=222";
$_SERVER['REQUEST_URI']  = "/aaa/?p=222";
$_SERVER['SCRIPT_NAME']  = "/aaa/index.php";
$_SERVER['PHP_SELF']     = "/aaa/index.php";

3,http://localhost/aaa/index.php?p=222&q=333
結果:
$_SERVER['QUERY_STRING'] = "p=222&q=333";
$_SERVER['REQUEST_URI']  = "/aaa/index.php?p=222&q=333";
$_SERVER['SCRIPT_NAME']  = "/aaa/index.php";
$_SERVER['PHP_SELF']     = "/aaa/index.php";

由實例可知:
$_SERVER["QUERY_STRING"]  獲取查詢 語句,實例中可知,獲取的是?後面的值
$_SERVER["REQUEST_URI"]   獲取 http://localhost 後面的值,包括/
$_SERVER["SCRIPT_NAME"]   獲取當前腳本的路徑,如:index.php
$_SERVER["PHP_SELF"]      當前正在執行腳本的文件名
 
 
 

$_SERVER['REQUEST_URI']和$_SERVER["HTTP_X_REWRITE_URL"]的區別

 

WordPress經過301重定向實現非首先域(非www)跳轉向原本是一個很簡單事情,因爲沒弄清楚$_SERVER['HTTP_X_REWRITE_URL'] 和$_SERVER['REQUEST_URI']的區別致使了循環重定向問題。
如今來具體研究下$_SERVER['HTTP_X_REWRITE_URL'] 和$_SERVER['REQUEST_URI']的區別
首先要糾正一部分的觀點就是IIS+PHP不支持$_SERVER['REQUEST_URI']
不是,不支持是PHP Version 版本的問題,php4.4.0不支持 $_SERVER['REQUEST_URI'],php5.2.5則增長了支持;php

$_SERVER['REQUEST_URI']經常使用來獲當前URL
例如:http://www.hujuntao.com/index.php?p=3
$_SERVER['REQUEST_URI']得到的就是/index.php?p=3這部分

$_SERVER["HTTP_X_REWRITE_URL"]則在IIS下得到的是當前URL,在apache下的值爲空html

例如:
當前URL:http://www.hujuntao.com/
IIS環境下:
$_SERVER['REQUEST_URI'] = /index.php
$_SERVER["HTTP_X_REWRITE_URL"] =/
apache環境下:
$_SERVER['REQUEST_URI'] = /
$_SERVER["HTTP_X_REWRITE_URL"] =」web

當前URL:http://www.hujuntao.com/index.php
IIS環境下:
$_SERVER['REQUEST_URI'] = /index.php
$_SERVER["HTTP_X_REWRITE_URL"] =/index.php
apache環境下:
$_SERVER['REQUEST_URI'] = /index.php
$_SERVER["HTTP_X_REWRITE_URL"] =」apache

相關文章
相關標籤/搜索