PHP friendly URL implementation. The code below is mainly pseudo-static implementation. search engines like to see URLs of other sites? Www. xxx. commoduleshowactionlistpage7 or htmlh
The following code mainly implements pseudo-static operations, which search engines like
Do you often see URLs of other sites like this?
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
This is the case.
Today, I will announce the implementation of this method and work out the simplest code independently.
The functions are as follows. they are not encapsulated into classes. They are mainly unnecessary and 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 a 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;
}
?>
Easy to use
$ _ GET = getQueryString ();
?>
But this does not work, so it can only be implemented
Http://www.xxx.com/index.php/module/show/action/list/page/7.
There is an additional index. php in the middle. we need to remove it and rewrite it.
But some files do not want this, such as style images.
Create a. htaccess file
RewriteEngine on
RewriteCond $1! ^ (Index. php | css | pics | themes | js | robots.txt)
RewriteRule ^ (. *) $ index. php/$1 [L]
Now, OK. test it now.
$ _ GET = getQueryString ();
Print_r ($ _ GET );
?>
Which of the following websites do you often see? Http://www.xxx.com/module/show/action/list/page/7 or html "> h...