Home > Backend Development > PHP Tutorial > Implementation of PHP friendly URL_PHP tutorial

Implementation of PHP friendly URL_PHP tutorial

WBOY
Release: 2016-07-13 17:35:15
Original
1163 people have browsed it

The following code is mainly a pseudo-static implementation, which search engines like

You often see URLs like this on other websites, right?
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
Like this
Today I will announce the implementation of this method and independently create the simplest code
The function is as follows. It is not encapsulated into a class, mainly because it is not necessary. It is more 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 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;
}
?>
It is very simple to use
$_GET= getQueryString();
?>
But this is not enough, this can only be achieved
http://www.xxx.com/index.php/module/show/action/list/page/7 This
has an extra index.php in the middle. Therefore, we have to remove it and have to re- Write
but you don’t want this for some files, such as style images, then put
in the condition to create a .htaccess file

RewriteEngine on
RewriteCond $1 !^(index.php|css|pics|themes|js|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Now it’s OK, let’s go test it now

$_GET= getQueryString();
print_r($_GET);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508354.htmlTechArticleThe following code is mainly a pseudo-static implementation. Search engines like that you often see the URL of other sites like this Right? http://www.xxx.com/module/show/action/list/page/7 or html">h...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template