PHP friendly URL implementation _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP friendly URL implementation. The code below is mainly pseudo-static implementation. search engines like to see URLs of other sites? Www. xxx. commoduleshowactionlistpage7 or htmlh

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
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
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 );
?>

Which of the following websites do you often see? Http://www.xxx.com/module/show/action/list/page/7 or html "> h...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.