PHP: how to implement pseudo-static website; php pseudo-static _ PHP Tutorial

Source: Internet
Author: User
PHP implements the pseudo-static website and php pseudo-static website. PHP: how to implement pseudo-static website. php: the mod_rewrite of Apache is powerful. This module can be used to implement pseudo-static website construction. The main steps are as follows: 1. how does PHP implement pseudo-static URLs and php pseudo-static URLs?

Apache mod_rewrite is relatively powerful. During website construction, this module can be used to implement pseudo-static.

The main steps are as follows:

1. check whether mod_rewrite is enabled in Apache. you can use the phpinfo () function provided by php to view the environment configuration and find "Loaded Modules", which lists all Modules enabled by apache2handler, if "mod_rewrite" is included, it is supported and you do not need to set it again. If "mod_rewrite" is not enabled, open "/apache/conf/" in the apache Directory and find httpd. in the conf file, find "LoadModule rewrite_module", and delete the "#" sign to use this function. If the "LoadModule" area is not found, you can add "LoadModule rewrite_module, modules/mod_rewrite.so" in the last line (Exclusive Line), and then restart the apache server. Then you can use the phpinfo () function to check the Environment configuration. "mod_rewrite" is the item.

2. how can I enable the apache server to support. htaccess for my local APACHE server: "htaccess? You only need to modify the httpd. conf settings of apache to enable APACHE to support ". htaccess. Open the httpd. CONF file in the conf Directory of the APACHE Directory, and find: Options FollowSymLinks AllowOverride None changed to Options FollowSymLinks AllowOverride All.

3. when creating a. htaccess file and creating a. htaccess file, you must note that the file cannot be directly created by using the save as menu in Notepad. in the file name window, enter ". htaccess" and click save.

4. rewrite rules are learned in the new. after the htaccess file, write the following content in it: RewriteEngine on # rewriteengine is the rewrite engine switch on to turn off RewriteRule ([0-9] {1,}) $ index. php? Id = $1 here, RewriteRule is a rewrite rule and a regular expression sentence ([0-9] {1,}) represents a number, $ indicates the end sign, indicating that it ends with a number! If you want to implement a pseudo-static page, the rules are as follows: RewriteEngine on RewriteRule ([a-za-z000000001, 00000000-(%0-9000000001, 00000000.html $ index. php? Action = $1 & id = $2 is in the regular expression, (a-za-z000000001, 00000000-(00000-9000000001, 00000000.html $ is the rule, index. php? Action = $1 & id = $2 is the format to be replaced. $1 represents the matching value of 1st parentheses, $2 represents the value of the second parenthesis, and so on! The PHP test script is as follows: index. the code in the PHP file is as follows: echo 'your Action value is :'. $ _ GET ['action']; echo ''; echo 'Id :'. $ _ GET ['id'];?>

In the browser address bar input: localhost/page-18.html output is: your Action value: page ID value: 18

Haha, rewrite successful!

I will share some of my personal experience on configuring pseudo-static data:

It's amazing to get started with pseudo-static access. In fact, it's very easy to think, that is, to configure several more virtual domain names on the server, similar to the real access url. Three steps

A. First, enable vhost_alias_moudle in the Apache module.

B. modify the httpd. conf file. in this file, search rewrite. find LoadModule rewrite_module modules/mod_rewrite.so and remove the previous #

C. modify this file, in the path D: \ wamp \ bin \ apache \ Apache2.2.21 \ conf \ extra under the httpd-vhosts.conf file, according to the example add a OK


ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "d:/wamp/www/dz"
ServerName localhost.www.dz.cn
ErrorLog "log/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common

D. configure hosts in path C: \ Windows \ System32 \ drivers \ etc

127.0.0.1 localhost.www.dz.cn restart the service. Success!

**************************************** * *********************************** Happy new year!

Note: Enter localhost.www.dz.cn in the browser to access the website. I add localhost to distinguish it from the official website. If you have any questions, contact me via QQ: 1024900614 to facilitate discussion and common progress!

All your pseudo-static rules are written in the. htaccess file. the file is loaded by default because it has been enabled. Write this. htaccess file to write regular expressions. learn some regular expressions!

Apache mod_rewrite is relatively powerful. During website construction, this module can be used to implement pseudo-static. The main steps are as follows: 1...

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.