What is pseudo-static? Three ways to implement PHP pseudo-static

Source: Internet
Author: User
Tags php script vars

Pseudo-Static is relatively true static, usually we to enhance the search engine friendly side, will be the article content generated static pages, but some friends in order to display some information in real time. Or you want to use dynamic scripting to solve some problems. You cannot display site content in a static manner. But this loses the friendly side of the search engine. How to find a middle method between the two, which produces pseudo-static technology. Is the display of a static page in the form of HTML, but in fact, a class of ASP dynamic script to deal with.

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.

/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:

/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

123456 if(preg_match("/\/(\d+),(\d+),(\d+)\.html/si",$path_info,$arr_path)){$gid     =intval($arr_path[1]); //取得值 1$sid     =intval($arr_path[2]);   //取得值100$softid   =intval($arr_path[3]);   //取得值8630}elsedie("Path:Error!");//相当于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:

123 <IfModule mod_rewrite.c>RewriteEngine On#RewriteCond %{ENV:SCRIPT_URL} (?:index|dispbbs)[-0-9]+.htmlRewriteRule ^(.*?(?:index|dispbbs))-([-0-9]+).html 1.php?__is_apache_rewrite=1&__rewrite_arg=2</IfModule>四 要实现asp帖子URL到php帖子的映射,在 第三步的<IfModule mod_rewrite.c>和</IfModule>之间添加:RewriteMap tolowercase int:tolowerRewriteCond %{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:

123 <?php/*功能:PHP伪静态化页面的实现具体用法:例如链接为:test.php/year/2006/action/_add.htmlmod_rewrite();$yearn=$_GET["year"];//结果为‘2006‘$action=$_GET["action"];//结果为‘_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);//这句是去掉尾部的.html或.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"];//结果为‘2006‘$action=$_GET["action"];//结果为‘_add‘echo $yearn;echo $action;?><?php/*

function: Implementation of PHP pseudo-static page
Specific usage:
For example, the link is: test.php/year/2006/action/_add.html

12 mod_rewrite();$yearn=$_GET["year"];//结果为‘2006‘$action=$_GET["action"];//结果为‘_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);//这句是去掉尾部的.html或.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"];//结果为‘2006‘$action=$_GET["action"];//结果为‘_add‘echo $yearn;echo $action;?>

What is pseudo-static? Three ways to implement the PHP pseudo-static introduction of the details, more attention to the PHP Chinese web other related articles!

What is pseudo-static? Three ways to implement PHP pseudo-static

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.