The following code is mainly a pseudo-static implementation, which search engines like You often see URLs like this on other websites, right? /** RewriteEngine on $_GET= getQueryString();
http://www.xxx.com/module/show/action/list/page/7
or
html">http://xx.com/module/show/action/show/ id/8.shtml with extension
or
http://xx.com/module/show/action/show/id/8?word=ss&age=11
Like this
Today I will announce the implementation of this method and independently create the simplest code
The function is as follows. It is not encapsulated into a class, mainly because it is not necessary. It is more convenient to use functions
* Get friendly URL access
*
* @accesspublic
* @return array
*/
function getQueryString(){
$_SGETS = explode("/",substr($_SERVER[PATH_INFO],1));
$_SLEN = count($_SGETS);
$_SGET = $_GET;
for($i=0;$i<$_SLEN;$i+=2){
if(!empty ($_SGETS[$i]) && !empty($_SGETS[$i+1])) $_SGET[$_SGETS[$i]]=$_SGETS[$i+1];
}
$ _SGET[m] = !empty($_SGET[m]) && is_string($_SGET[m]) ? trim($_SGET[m]).Action : indexAction;
$_SGET[a] = !empty($ _SGET[a]) && is_string($_SGET[a]) ? trim($_SGET[a]) : run;
return $_SGET;
}
/**
* Generate link URL
*
* @accesspublic
* @param array $arr
* @return string
*/
function setUrl($arr){
global $Global;
$queryString=;
if($Global[urlmode]==2){
foreach($arr as $k=> $v){
$queryString.=$k./.$v./;
}
}
$queryString.=$Global[urlsuffix];
return $queryString;
}
?>
It is very simple to use
$_GET= getQueryString();
?>
But this is not enough, this can only be achieved
http://www.xxx.com/index.php/module/show/action/list/page/7 This
has an extra index.php in the middle. Therefore, we have to remove it and have to re- Write
but you don’t want this for some files, such as style images, then put
in the condition to create a .htaccess file
RewriteCond $1 !^(index.php|css|pics|themes|js|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Now it’s OK, let’s go test it now
print_r($_GET);
?>