Rewrite Learning notes Summary _win server

Source: Internet
Author: User
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);
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.