The pseudo static implementation based on php is described in detail

  • 2020-06-01 08:37:44
  • OfStack

1. Operate the implementation according to $_SERVER['PATH_INFO'].
For example, the address of your website is show_new.php/look-id-1.shtml
You echo $_SERVER['PATH_INFO'] will come out with/look-id-1.shtml saw this and I think you get the idea.
The complete demo

$conn=mysql_connect("localhost","root","root")or dir(" The connection fails ");
$sql="select * from news";
echo "<h1> News list </h1>";
echo "<a href='add_news.html'> Add the news </a><hr/>";
echo "<table>";
echo "<tr><td>id</td><td> The title </td><td> Check the details </td><td> Modify the news </td></tr>";
 echo "<tr><td>{$row['id']}</td><td>{$row['title']}</td><td><a href='show_new.php/look-id-{$row['id']}.shtml'> Check the details </a></td><td><a href='#'> Modify the page </a></td></tr>";
// The red address on the top should have been show_news.php?act=look&id={$row['id']}
echo "</table>";
// Close the resource 

show_new php page

mysql_query("set names utf8");
 $pa = $_SERVER['PATH_INFO'];
//$pa   The printed value is   /look-id-1.html
// Obtained through regular expression matching url address 
 $act = $arr[1]; // This is requested look methods 
 $id = $arr[3];  // This is what we get id  value 
 $sql="select * from news  where id= $id";
 $res = mysql_fetch_assoc($res);
 echo $res['title']."<hr>".$res['content'];
 echo "url Illegal address ";

I think you get the idea when you look at this one up here. In fact, we don't use it that much. Let me give you the second one

2. According to the configuration.htaccess.
So how do you create an htaccess file, create a notepad in the root directory of the website and then double click open and click save as file name as written
.htaccess, save type select all files, code select utf-8 code okay so that's where you see this.htaccess file in the directory

First turn on,AllowOverride None, AllowOverride All in two places

For example, href address is one_new-id-1.shtml // this means one_new.php? id = 1
So this is htaccess right here

<IfModule rewrite_module>
# Write your rewrite The rules 
RewriteEngine On
#  Multiple rules can be configured, matching from top to bottom 
RewriteRule  one_new-id-(\d+)\.shtml$ one_new.php?id=$1 // Here, $1  It stands for no 1 A parameter? 
RewriteRule  abc_id(\d+)\.html$     error.php
# Set up the 404 error 
#ErrorDocument  404  /error.php

echo $_GET['id'] will definitely output the value of id on one_new.php

Note: the current personal ability can only write here I will gradually improve
Leave me a message if you have any questions

Related articles: