There are several ways to implement PHP pseudo static:
1. According to $_server[' Path_info '] to operate the implementation.
For example, the address of your website is http://127.0.0.1/show_new.php/look-id-1.shtml.
The result of your echo $_server[' Path_info ' will be/look-id-1.shtml see this I think you may have understood.
The full demo
index.php
index.php
$conn =mysql_connect ("localhost", "root", "root") or dir ("
Connection Failed");
mysql_select_db ("Tb_demo", $conn);
$sql = "SELECT * from News";
$res =mysql_query ($sql);
Header ("Content-type:text/html;charset=utf-8");
echo "
show_new.php page
show_new.php
Header ("Content-type:text/html;charset=utf-8");
$conn =mysql_connect ("localhost", "root", "root");
mysql_select_db ("Tb_demo", $conn);
mysql_query ("Set names UTF8");
$pa = $_server[' Path_info '];
$PA Printed value is /look-id-1.html
//The URL address that is obtained through a regular expression match
if (Preg_match ('/^\/look)-(ID)-([\d]) \. shtml$/', $pa, $arr)) {
$act = $arr [1];//This is the requested look method
$id = $arr [3]; This is the ID value obtained
$sql = "SELECT * FROM News where id= $id";
$res =mysql_query ($sql);
$res = Mysql_fetch_assoc ($res);
echo $res [' title '].
See the above this I think you must understand it in fact this way with a few of the following for everyone to say the second method of AH
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/
2. According to the configuration. htaccess to achieve.
Let's say first. htaccess file how to create it, in the site root directory to build a notepad and then double-click Open Click Save as file name written
. htaccess, save type Select all files, encode select Utf-8 code okay this is what you see in the catalogue. htaccess file.
First on Apache Mod_rewrite.so,allowoverride None here are replaced by allowoverride all
such as the HREF address written one_new-id-1.shtml///This means one_new.php?id=1
Here's the. htaccess can write that.
<IfModule rewrite_module>
#写你的rewrite规则
RewriteEngine On
# 可以配置多个规则,匹配的顺序是从上到下
RewriteRule one_new-id-(\d+)\.shtml$ one_new.php?id=$1 //这里的$1 代表的是第一个参数啊
RewriteRule abc_id(\d+)\.html$ error.php
#设置404错误
#ErrorDocument 404 /error.php
</IfModule>
Your one_new.php page echo $_get[' id ' will definitely output the ID's value.
Description: This current personal ability can only be written here, I will gradually improve the