search
HomeBackend DevelopmentPHP TutorialWhat is Pseudo-Static state? Introduction to three methods to implement pseudo-static in PHP

Pseudo-static is relative to real static. Usually, in order to enhance the friendliness of search engines, we generate static pages from article content, but some friends want to display some information in real time. Or you want to use dynamic scripts to solve some problems. Website content cannot be displayed in a static manner. But this loses the friendliness to search engines. How to find a middle method between the two, which gave rise to pseudo-static technology. What is displayed is a static page such as HTML, but it is actually processed using dynamic scripts such as ASP.

Pseudo-static aka: URL rewriting

Mainly for SEO. (What is SEO? You don’t have to ask me this. Haha~ Those who work on the Internet don’t understand SEO~~~~)

method one:

For example, this page

/soft.php/1,100,8630.html

In fact, the script being processed is soft.php and the parameter is 1,100,8630

Equivalent to soft.php?a=1&b=1=100&c=8630, but this URL is too difficult to remember. Search engines don’t like it either.

True static is just fully generated HTML.

Direct output when the client accesses. No need for script explanation. It will have very good results when the traffic is very large (such as when there are millions of visits every day). In other words, this HTML page actually exists on the server side.

Of course, when the traffic of your website is not that large. URL rewriting is the best method (in my personal opinion, load balancing can be considered when there is heavy traffic. It doesn’t matter either)

There are many methods for URL rewriting, including APACHE and IISREWRITE. Even PHP scripts can handle it directly. For example, in the above example, the PHP script handles it directly (the advantage of this method is that it directly reduces the pressure on the WEB server when there is a large amount of traffic. PS: This is also a personal opinion:

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

Let's take a program as an example to talk about the PHP pseudo-static program implementation method. In fact, I have posted this method in other forum communities before

Take the program as an example:

/soft.php/1,100,8630.html

CODE:

//Use the server variable to obtain the PATH_INFO information. In this example, it is /1,100,8630.html, which is the part after the execution 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]); //取得值 1
$sid     =intval($arr_path[2]);   //取得值100
$softid   =intval($arr_path[3]);   //取得值8630
}else die("Path:Error!");
//相当于soft.php?gid=1&sid=100&softid=8630


//It's that simple. ~)

Method Two:

1. Open the Apache configuration file httpd.conf.

2. Remove

in front of #LoadModule rewrite_module modules/mod_rewrite 3. Add:

<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

to httpd.conf 5. Save httpd.conf and restart Apache

Method three:

<?php/*功能:PHP伪静态化页面的实现具体用法:例如链接为:test.php/year/2006/action/_add.htmlmod_rewrite();$yearn=$_GET["year"];//结果为&#39;2006&#39;$action=$_GET["action"];//结果为&#39;_add&#39;
*/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"];//结果为&#39;2006&#39;$action=$_GET["action"];//结果为&#39;_add&#39;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

mod_rewrite();$yearn=$_GET["year"];//结果为&#39;2006&#39;$action=$_GET["action"];//结果为&#39;_add&#39;
*/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"];//结果为&#39;2006&#39;$action=$_GET["action"];//结果为&#39;_add&#39;echo $yearn;echo $action;?>

The above is the detailed content of What is Pseudo-Static state? Introduction to three methods to implement pseudo-static in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools