PHP pseudo-static getting started based on tutorials

Source: Internet
Author: User

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 (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: Copy code

<Ifmodule mod_rewrite.c> # Write in liunx

Rewriteengine on

Rewriterule (%a-za-z%}1,%}-(%0-9%}1,%}.html $ index. php? Action = $1 & id = $2

</Ifmodule>


([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: Copy code

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

<A href = "/about_22/"> about us </a>

The page we visit is the same as the page we visit below.

<A href = "/about. php? Id = 22 "> about us </a>


2. php code

For example: http://www.xxxx.com/soft.php/1,100,8630.html

The Code is as follows: Copy code

<? 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 .~)
?>

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.