For example, below, I want to implement a URL like this:
http://xxx.com/0725
http://xxx.com/0726
http://xxx.com/0727
...
Above xxx.com is a test site for historical content such as "Today is". The link above means to show what happened in the history of July 25, something like that. This looks very beautiful, neat. Otherwise, the possible address is:
Http://xxx.com/index.php?t ...
Http://xxx.com/index.php?t ...
Http://xxx.com/index.php?t ...
...
Now I just want to realize to hide index.php?today=. Here's the code:
1..htaccess file
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritebase/
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewriterule ^ ([0-9]+) $/index.php?today=$1
</IfModule>
Bold word Here I explain, the other in this format, I do not understand the specific now.
[0-9] means that the parameter can only be 0~9 these numbers, if you want to include any characters, change to:
Rewriterule ^ (. +) $/index.php?today=$1
Here [0-9] was replaced. , this. Represents any character. Of course the complexity is still very complicated, we don't care for a while.
2.index.php file
Copy Code code as follows:
<?php
Rewrite test
$uid =$_request[' Today '];
?>
<HTML>
<HEAD>
<title>rewrite Test </TITLE>
</HEAD>
<body bgcolor= "#FFFFFF" text= "#000000" link= "#0000FF" vlink= "#800080" >
Today is <?php echo $today;? Look at what's going on in history today. <br>
......
</BODY>
</HTML>
Here the parameters will be passed to the index.php file in the $today, in this program, you can according to the parameters, processing, such as querying the database, do operations, and so on, and then display the corresponding data out, it can be.
Implementation Method 2
Copy Code code as follows:
<?php
URL Example: soft.php/1,100,8630.html
Using the server variable to get path_info information in this case,/1,100,8630.html is the part that follows the script name
if (@ $path _info =$_server["Path_info"]) {
if (Preg_match ("/\/(\d+), (\d+), (\d+) \.html/si", $path _info, $arr _path)) {
$gid =intval ($arr _path[1]); Get a value of 1
$sid =intval ($arr _path[2]); Get a value of 100
$softid =intval ($arr _path[3]); Get a value of 8630
Equivalent to soft.php?gid=1&sid=100&softid=8630
}else die ("path:error!");
}else die ("path:nothing!");
Echo ($gid);
Echo ("<br>");
Echo ($SID);
Echo ("<br>");
Echo ($softid);
?>