Three methods to implement PHP pseudo-static pages

Source: Internet
Author: User

PHP pseudo-static writing-one

Pseudo static name: URL rewriting

Mainly for SEO. (What is SEO? You don't have to ask me this. Haha ~ If you do not understand SEO, then ~~~~)

Method 1:

For example, this webpage

Http://www.bkjia.com/soft. php/1,100,8630.html

In fact, the soft. php parameter is 1,100,863 0.

Equivalent to soft. php? A = 1 & B = 1 = 100 & c = 8630, but such a URL is too hard to remember. Search engines do not like it either.

Real static only completely generates HTML.

Output directly when accessing the client. No script explanation is required. When the traffic is very large (for example, when there are millions of visits each day), it will play a very good effect. That is to say, the server actually has this HTML page.

Of course, when the traffic on your website is not that large. URL rewriting is the best method (in my opinion, Server Load balancer can be considered when the traffic is high. It also does not matter)

There are many URL rewriting methods, such as APACHE and IISREWRITE. Even PHP scripts can be processed directly. For example, in the above example, PHP scripts are directly processed (the advantage of this method is to directly reduce the pressure on the WEB server when the traffic is high. PS: also personal opinion:

========================================================== ==========

The following uses a program as an example to describe the PHP pseudo-static program implementation method. In fact, this method has already been released in other forums.

Program example:

Http://www.bkjia.com/soft. php/1,100,8630.html

CODE:

// Use the server variable to obtain the PATH_INFO information. In this example, It is/, 8630.html, that is, the part after the execution Script Name.

If (@ $ path_info = $ _ SERVER ["PATH_INFO"]) {

// Regular Expression Matching Parameters

If (preg_match ("// (\ d +), (\ d +), (\ d +) \. html/si", $ path_info, $ arr_path )){

$ Gid = intval ($ arr_path [1]); // get the value 1

$ Sid = intval ($ arr_path [2]); // get the value 100

$ Softid = intval ($ arr_path [3]); // get the value 8630

} Else die ("Path: Error! ");

// Equivalent to soft. php? Gid = 1 & sid = 100 & softid = 8630


// It's that simple .~)

Method 2:

1. Open the configuration file httpd. conf of Apache.

2. Remove the # LoadModule rewrite_module modules/mod_rewrite before #.

3. Add the following in httpd. conf:

<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteCond % {ENV: SCRIPT_URL }(? : Index | dispbbs00000000-0-900000000.html
RewriteRule ^ (.*? (? : Index | dispbbs00000000-(-0-9000000000000.html 1.php? _ Is_apache_rewrite = 1 & __ rewrite_arg = 2
</IfModule>

4. To map asp post URLs to php posts, add the following between <IfModule mod_rewrite.c> and </IfModule> in step 3:

RewriteMap tolowercase int: tolower
RewriteCond % {QUERY_STRING }(? : Boardid | page | id | replyid | star | skin) = d + [NC]
RewriteRule ^ (.*(? : Index | dispbbs). asp 1.php? {Tolowercase: % {QUERY_STRING }}&__ is_apache_rewrite = 1

5. Save httpd. conf and restart Apache

Method 3:

<? Php
/*
Function: PHP pseudo-static page implementation
Usage:
For example, the link is test. php/year/2006/action/_add.html.
Mod_rewrite ();
$ Yearn = $ _ GET ["year"]; // The result is 2006'
$ Action = $ _ GET ["action"]; // The result is '_ add'

*/
Function mod_rewrite (){
Global $ _ GET;
$ Nav = $ _ SERVER ["REQUEST_URI"];
$ Script_name = $ _ SERVER ["SCRIPT_NAME"];
$ Nav = substr (ereg_replace ("^ $ script_name", "", urldecode ($ nav), 1 );
$ Nav = preg_replace ("/^. ht (m) {1} (l) {0, 1} $/", "", $ nav); // the end of this sentence is .htmlor .htm.
$ Vars = explode ("/", $ nav );
For ($ I = 0; $ I <Count ($ vars); $ I ++ = 2 ){
$ _ GET ["$ vars [$ I]"] = $ vars [$ I + 1];
}
Return $ _ GET;
}
Mod_rewrite ();
$ Yearn = $ _ GET ["year"]; // The result is 2006'
$ Action = $ _ GET ["action"]; // The result is '_ add'
Echo $ yearn;
Echo $ action;
?>

<? Php
/*
Function: PHP pseudo-static page implementation
Usage:
For example, the link is test. php/year/2006/action/_add.html.
Mod_rewrite ();
$ Yearn = $ _ GET ["year"]; // The result is 2006'
$ Action = $ _ GET ["action"]; // The result is '_ add'

*/
Function mod_rewrite (){
Global $ _ GET;
$ Nav = $ _ SERVER ["REQUEST_URI"];
$ Script_name = $ _ SERVER ["SCRIPT_NAME"];
$ Nav = substr (ereg_replace ("^ $ script_name", "", urldecode ($ nav), 1 );
$ Nav = preg_replace ("/^. ht (m) {1} (l) {0, 1} $/", "", $ nav); // the end of this sentence is .htmlor .htm.
$ Vars = explode ("/", $ nav );
For ($ I = 0; $ I <Count ($ vars); $ I ++ = 2 ){
$ _ GET ["$ vars [$ I]"] = $ vars [$ I + 1];
}
Return $ _ GET;
}
Mod_rewrite ();
$ Yearn = $ _ GET ["year"]; // The result is 2006'
$ Action = $ _ GET ["action"]; // The result is '_ add'
Echo $ yearn;
Echo $ action;
?>

This method is the most direct !~~~ Haha... the water and wood for you to provide...

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.