Home > Backend Development > PHP Tutorial > Implementation of babyliss pro perfect curl php friendly URL (recommended by vomiting blood)

Implementation of babyliss pro perfect curl php friendly URL (recommended by vomiting blood)

WBOY
Release: 2016-07-29 08:38:59
Original
1239 people have browsed it

Implementation of friendly URLs (recommended by Hematemesis)
You often see the URLs of other sites looking like this, right?
http://www.xxx.com/module/show/action/list/page/7
or
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 one The code
function is as follows, it is not encapsulated into a class, mainly because it is not necessary, it is more convenient to use functions

Copy the code 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 link 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;
}
?> _GET= getQueryString();
?>



But this is not enough, this can only achieve

http://www.xxx.com/index.php/module/show/action/list/page/7 like this There is an extra index.php in the middle, so we have to remove it and have to rewrite itBut some files don’t want this, such as style pictures, so put it in the conditionsCreate an .htaccess file


Copy the code

The code is as follows:


RewriteEngine on
RewriteCond $1 !^(index.php|css|pics|themes|js|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]


Now it's OK, go and test it quickly

Copy the code

The code is as follows:



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

?>

The above introduces the implementation of babyliss pro perfect curl PHP friendly URL (recommended by vomiting blood), including the content of babyliss pro perfect curl. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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