Php url static _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP implements URL static. Php Tutorial real-time url phpphp real-time pseudo-static another type of pseudo-static formula, that is, the user and the search engine see the static page with the suffix of .html, but in fact it is still a dynamic program, php Tutorial implements url static

Php implements pseudo-static

There is another pseudo-static formula, that is, the user and the search engine see the static page with the suffix of .html, but in fact it is still a dynamic program, but it is disguised in some way.

There are two ways to achieve this:

The first method is to implement static link through url rewrite on the web server. the following uses apache as an example to describe the implementation method. For users with server configuration permissions, we recommend that you use the mod_rewrite module of apache. we assume that the mod_rewrite module has been installed. Open the apache configuration file, find the corresponding host, and add the following code:

Rewriteengine on
Rewriterule ^/abc/([a-z] +)/(%0-9%%%%%.html $/abc. php? Action = $1 & id = $2


Then execute service httpd reload in shell, and let apache reload the configuration.

But for most of us, we only purchase space and have no permission to modify the apache configuration file. Is there any way to change the configuration file? No, of course, there is a way to first enter the root directory of our space (such as public_html), and then create a file named. htaccess. The content of this file is basically as follows:

Rewriteengine on
Rewritebase/
Rewriterule ^ post/(%0-9%%%%.htm read. php? 1
Rewriterule ^ post/(%0-9%%%%%_(%0-9%%%%%.htm read. php? 1 & page = 2
Rewriterule ^ post/(%0-9%%%%%_(%0-9%%%%%%%%%%_(%0-9%%%%%.htm read. php? 1 & page = 2 & = 3

Php program writing

Function mod_rewrite (){
If (isset ($ _ server ['path_info']) {
$ Url = substr ($ _ server ['path_info'], 1 );
$ Url = explode ('/', $ url );
Foreach ($ url as $ key => $ value ){
If ($ key % 2! = 1 ){
If ($ value! = '') $ _ Get [$ value] = $ url [$ key + 1];
$ Querystring [] = $ value. '='. $ url [$ key + 1];
}
}
$ _ Server ['query_string '] = implode ("&", $ querystring );
$ _ Server ['php_self '] = substr ($ _ server ['php_self']

, 0, strpos ($ _ server ['php_self '],'. php') + 4 );
$ _ Server ['request_uri '] = $ _ server ['php_self']

.'? '. $ _ Server ['query_string'];
}
}

Php implements pseudo-static, and there is another pseudo-static formula, that is, the user and the search engine see the static page with the suffix of .html, but in fact it is still a dynamic program ,...

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.