PHP implementation MOD REWRITE redirection function

xiaoxiao2021-03-06  99

Apache's RE_WRITE setting is really complicated, looking for a long time, finally found this functionality implemented with PHP imitation:

Transfer parameters: http://localhost/websamples/rewrite.php/Name/jxyuhua/sex/male

Analysis parameters:

Get parameter string / Name / jxyuhua / sex / malearray ([0] => Name [1] => jxyuhua [2] => sex [3] => Male)

-------------------------------------------------- -----------------------------------------

/ * This method is only used in Apache Server * /

IF (isset ($ _ server [pat_info])) // If Path_info is available, pay attention to Apache2 is not available by default

$ query_string = $ _server [pat_info];

Else {

$ query_string = str_replace ($ _ server [script_name], "", $ _ server [php_self]);

//or

$ query_string = str_replace ($ _ server [script_name], "", $ _ server [request_uri]);

}

IF (Empty ($ query_string))

ECHO "no parameters";

Else {

Echo "Get parameter string $ query_string
";

$ args = split ("/", substr ($ query_string, 1)); // Split Normal Group

Print_r ($ args); / / View the resulting parameter array. Note that due to the passing parameters, there is no variable name information, you need to be carefully determined according to the meaning of the parameters.

}

?>

转载请注明原文地址:https://www.9cbs.com/read-123541.html

New Post(0)