How PHP implements pseudo-static website

Source: Internet
Author: User
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 if mod_rewrite is enabled for Apache. You can use the phpinfo () function provided by php to view the environment configuration and find LoadedModules. All modules enabled by apache2handler are listed.

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 if mod_rewrite is enabled for Apache. You can use the phpinfo () function provided by php to view the environment configuration and find Loaded Modules. All Modules enabled by apache2handler are listed.

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!

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.