PHP URL static

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags .url apache configuration example file html installed it is

php to achieve pseudo-static

Another is the pseudo-static mode, that is, users and search engines to see the static HTML page suffix, but in fact it is a dynamic program, but somehow disguised.

There are two ways to do this:

The first is through the web server, URL rewrite link static, the following example to explain the way to achieve it. For users with server configuration permissions, it is recommended to use apache's mod_rewrite module, assuming that the mod_rewrite module is already installed. Open the apache configuration file, find the appropriate host part, add the following code:

rewriteengine on
rewriterule ^ / abc / ([az] +) / ([0-9] +). html $ /abc.php?action=$1&id=$2
Then execute the service httpd reload in the shell, so that apache reload configuration just fine.

But for most of us, the only thing we buy is space, and there's no way to change apache's configuration file. Is there any way? No, of course there is a way, first of all, we go to the root of our space (like public_html) and then create a file named .htaccess. The basic content of this document is 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 written

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'];
}
}

Related Article

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.