Implementation of friendly URLs (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
The functions are as follows. They are not encapsulated into classes. They are mainly unnecessary and convenient to use functions.
Copy code The Code is as follows: <? PHP
/**
* 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 useCopy codeThe Code is as follows: <? PHP
$ _ 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 FileCopy codeThe 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.Copy codeThe Code is as follows: <? PHP
$ _ Get = getquerystring ();
Print_r ($ _ Get );
?>