Php friendly URL implementation (recommended for vomiting blood ). The implementation of friendly URLs (recommended for vomiting blood). do you often see URLs on other sites like this? Www. xxx. commoduleshowactionlistpage7 or xx. commoduleshowactionsh friendly URL implementation (recommended for vomiting blood)
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.
The code is as follows:
/**
* Get friendly URL access
*
* @ Access public
* @ 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
*
* @ Access public
* @ 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
The code is as follows:
$ _ 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
The code is as follows:
RewriteEngine on
RewriteCond $1! ^ (Index \. php | css | pics | themes | js | robots \. txt)
RewriteRule ^ (. *) $ index. php/$1 [L]
Now, OK. test it now.
The code is as follows:
$ _ GET = getQueryString ();
Print_r ($ _ GET );
?>
Refer (vomit blood recommended) do you often see URLs on other sites like this? Http://www.xxx.com/module/show/action/list/page/7 or http://xx.com/module/show/action/sh...