For the implementation of PHP-friendly URLs, read the implementation of PHP-friendly URLs. the following code mainly describes the implementation of pseudo-static URLs. do you often see URLs on other websites like this? Invalid.
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
The http://xx.com/module/show/action/show/id/8.shtml with an 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 );
?>