1. Operate the implementation according to $_server[' Path_info ').
For example, your site's address is http://127.0.0.1/show_new.php/look-id-1.shtml.
You echo $_server[' Path_info ' come out of the results will be/look-id-1.shtml see this I think you may already understand.
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
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 the printed value is /look-id-1.html//the URL address obtained by the regular expression match if (Preg_match ('/^\/(look)-( ID)-([\d]) \.shtml$/', $pa, $arr)) {$act = $arr [1];//This is the look method of the request $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 $re s[' title ']. "
See the above I think you must understand that this way with a few of the following to everyone said the second method of AH
2. Implement according to the configuration. htaccess.
Let's start with the. htaccess file, create a notepad in the root directory of the Web site and double-click the Save as file name to write
. htaccess, save type Select all files, encode select Utf-8 encoded well this is what you see in the directory of this. htaccess file now
First in Apache Open Mod_rewrite.so,allowoverride None Here are two replacements for allowoverride all
For example, the href address is written one_new-id-1.shtml//This means one_new.php?id=1
This is where the. htaccess can write.
<ifmodule rewrite_module> #写你的rewrite规则RewriteEngine on# can configure multiple rules, the order of matching is from top to bottom rewriterule one_new-id-(\d+) \.shtml$ one_new.php?id=$1//Here is the first parameter Ah rewriterule abc_id (\d+) \.html$ error.php# set 404 error # ErrorDocument 404 /error.php</ifmodule>
Your one_new.php page echo $_get[' id ' will definitely output the value of the ID.