PHP pseudo-static entry is based on the tutorial. In php, we can use apache to implement pseudo-static or php operations, but currently I only know apache's pseudo-static and php code's pseudo-static. Apache pseudo-static html (in php, we can use apache to implement pseudo-static or php operations, but currently I only know apache pseudo-static and php code pseudo-static.
Apache pseudo-static html (URL Rewrite) setting method
Phpma: Open the configuration file httpd. conf of Apache.
Phpma 2: # LoadModule rewrite_module modules/mod_rewrite # Remove
1. apache
Now we can implement a pseudo-static page, and write down the rules below:
| The code is as follows: |
|
|
# Write in liunx
Rewriteengine on
Rewriterule (%a-za-z%}1,%}-(%0-9%}1,%}.html $ index. php? Action = $1 & id = $2
|
([A-za-z000000001, 00000000-(%0-9000000001, 00000000.html $ is the rule, index. php? Action = $1 & id = $2 is the format to be replaced. $1 indicates the matching value of the first parenthesis, and $2 indicates the second.
Restart apache
2. create a new file named. htaccess in the directory.
. Htaccess file writing
Create a file under the root directory of the website named. htaccess. the writing method is as follows:
| The code is as follows: |
|
|
RewriteEngine on # enable rewrite
RewriteRule ^/$ index. php # indicates that you can access index. php "/".
RewriteRule ^ about _ (d *)/$ about/about. php? Id = $1 # indicates that about_22/can be used to access about/about. php? Id = 22 page. Note: $ the previous "/"
RewriteRule ^ about _ (d * logs .html $ about/about. php? Id = $1 could users use about_22.html to access about/about. php? Id = 22 page RewriteRule ^ news _ (d *) _ (d * pai.html $ news/news. php? Id = $1 & page = $2 webpage users can use news_11_2.html to access news/news. php? Id = 11 & page = 2 page. $1 indicates the first parameter, and $2 indicates the second parameter. |
We can see from the above that if we have the following link
About Us
The page we visit is the same as the page we visit below.
About Us
2. php code
For example: http://www.xxxx.com/soft.php/1,100,8630.html
| The code is as follows: |
|
|
<? Php
// Use the server variable to obtain the PATH_INFO information. In this example, it is/, 8630.html, that is, the part after the execution script name.
If (@ $ path_info = $ _ SERVER ["PATH_INFO"]) {
// Regular expression matching parameters
If (preg_match ("// (d1_success, (d1_success, (d1_0000.html/si", $ path_info, $ arr_path )){
$ Gid = intval ($ arr_path [1]); // get the value 1
$ Sid = intval ($ arr_path [2]); // get the value 100
$ Softid = intval ($ arr_path [3]); // get the value 8630
} Else die ("Path: Error! ");
// Equivalent to soft. php? Gid = 1 & sid = 100 & softid = 8630
} Else die ('path: Nothing! ');
// It's that simple .~)
?> |
Apache pseudo-static and php code pseudo-static. Apache pseudo-static html (URL Rewri...