The following code is mainly a pseudo-static implementation. Search engines like that
you often see URLs of other sites like this, right?
http://www.xxx.com/module/show/action/list/page/7
or
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
That's it. Today I will announce the implementation of this method, and separate the simplest code function as follows. It is not encapsulated into classes, mainly because it is not necessary. It is more convenient to use functions
<?php
/**
* 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;
}
?>
Very simple to use
<?php
$_GET= getQueryString();
?>
But this is not enough, this can only be achieved
http://www.xxx.com/index.php/module/show/action/list/page/7 There is an extra index.php in the middle. Therefore, we have to remove it and have to rewrite it. But some files are not If you want this, for example, style pictures, then create a .htaccess file in the condition
RewriteEngine on
RewriteCond $1 !^(index.php|css|pics|themes|js|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Now it’s OK, go and test it now
<?php
$_GET= getQueryString();
print_r($_GET);
?>