Three ways to implement PHP pseudo-static pages _php Tutorial

Source: Internet
Author: User
Tags vars
PHP pseudo-static notation--One

Pseudo-static name: URL rewrite

Mainly for the purpose of SEO and born. (What is SEO?) You don't have to ask me that. Hehe ~ Do not understand the network SEO that is ~ ~ ~)

Method One:

Like this page.

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

The script that is actually processed is the soft.php parameter of 1,100,8630

The equivalent of soft.php?a=1&b=1=100&c=8630 only such URLs are too difficult to remember. Search engines don't like it either.

True static just completely generates HTML.

Direct output when the client accesses it. No scripting explanation. It works well when traffic is very large, such as millions of visits per day. That is to say, the server side actually exists this HTML page.

Of course, the traffic on your site is not that big. URL rewriting is the best method (personal view, when large traffic can be considered load balanced.) also no relationship)

There are many ways to rewrite the URL, apache,iisrewrite. Even PHP scripts can be processed directly. For example, in the example above, the PHP script is processed directly (the advantage of this method is that it reduces the pressure of the Web server directly when the traffic is large.) PS: Also a personal point of view:

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

The following is a procedure for the example of PHP pseudo-static program implementation method, in fact, this method I have been in other forum community has been sent

Program for example:

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

CODE:

Use the server variable to get path_info information in this case,/1,100,8630.html is the part that executes the script name.

if (@ $path _info =$_server["Path_info"]) {

Regular match parameters

if (Preg_match ("/\/(\d+), (\d+), (\d+) \.html/si", $path _info, $arr _path)) {

$gid =intval ($arr _path[1]); Get value 1

$sid =intval ($arr _path[2]); Get Value 100

$softid =intval ($arr _path[3]); Get Value 8630

}else die ("path:error!");

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


It's so simple. ~

Method Two:

One opens the Apache configuration file httpd.conf.

Two will #loadmodule Rewrite_module Modules/mod_rewrite front of the # removed

Three additions in httpd.conf:


Rewriteengine on
#RewriteCond%{env:script_url} (?: Index|dispbbs) [ -0-9]+.html
Rewriterule ^ (. *? (?: Index|dispbbs))-([ -0-9]+). HTML 1.php?__is_apache_rewrite=1&__rewrite_arg=2

Four to implement the ASP post URL to the PHP post mapping, in the third step between and add:

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

Five save httpd.conf and restart Apache

Method Three:

/*
function: Implementation of PHP pseudo-static page
Specific usage:
For example, the link is: test.php/year/2006/action/_add.html
Mod_rewrite ();
$yearn =$_get["Year"];//result for ' 2006 '
$action =$_get["Action"];//result for ' _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);//This sentence is removed from the tail. html or. htm
$vars = Explode ("/", $nav);
for ($i =0; $i<>
$_get["$vars [$i]"]= $vars [$i +1];
}
return $_get;
}
Mod_rewrite ();
$yearn =$_get["Year"];//result for ' 2006 '
$action =$_get["Action"];//result for ' _add '
Echo $yearn;
Echo $action;
?>

/*
function: Implementation of PHP pseudo-static page
Specific usage:
For example, the link is: test.php/year/2006/action/_add.html
Mod_rewrite ();
$yearn =$_get["Year"];//result for ' 2006 '
$action =$_get["Action"];//result for ' _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);//This sentence is removed from the tail. html or. htm
$vars = Explode ("/", $nav);
for ($i =0; $i<>
$_get["$vars [$i]"]= $vars [$i +1];
}
return $_get;
}
Mod_rewrite ();
$yearn =$_get["Year"];//result for ' 2006 '
$action =$_get["Action"];//result for ' _add '
Echo $yearn;
Echo $action;
?>

This method is the most direct ... Personally think!~~~ hehe. Shuimu to provide you with ...

http://www.bkjia.com/PHPjc/478694.html www.bkjia.com true http://www.bkjia.com/PHPjc/478694.html techarticle PHP pseudo-static notation-one pseudo-static name: URL Rewrite is mainly for the purpose of SEO. (What is SEO?) You don't have to ask me that. Hehe ~ Do not understand the network SEO that is ~ ~ ~ ...

  • 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.