PHP open pseudo-static configuration

Source: Internet
Author: User

1. Detect if Apache is turning on mod_rewrite function

The Phpinfo () function provided by PHP can be used to view the environment configuration and find "Loaded Modules", which lists all the modules that have been opened by Apache2handler, and if it includes "mod_rewrite", it is already supported and no longer required to continue setting.

If "Mod_rewrite" is not turned on, open the directory Apache directory "/apache/conf/", find the httpd.conf file, and then find "LoadModule rewrite_module", the Front "#" This feature is used when the number is deleted.

If you do not find the "LoadModule" area, you can add "LoadModule rewrite_module, modules/mod_rewrite.so" (exclusive row) on the last line, and then restart the Apache server. The Phpinfo () function then looks at the environment configuration with "Mod_rewrite" as the item.

2. Let Apache server support. htaccess How to make your local Apache server support: "Htaccess"? Just modify Apache's httpd.conf settings to allow Apache to support ". htaccess".

Open the httpd.conf file in the Conf directory of the Apache directory, find: Options followsymlinks allowoverride None change to Options FollowSymLinks allowoverride All on the line.

3. When establishing the. htaccess file, be aware that the. htaccess file cannot be built directly by using the Save As menu in Notepad, enter: ". htaccess" in the File name window, then click Save.

4.rewrite Rule Learning

After the new. htaccess file is created, it is written in the following: Rewriteengine on #rewriteengine为重写引擎开关on为开启off为关闭 rewriterule ([0-9]{1,}) $index. php?id =$1 here, Rewriterule is the rewrite rule, is a regular expression of the sentence, ([0-9]{1,}) is composed of numbers, $ represents the end of the flag, indicating the end of the number!

If you want to implement a pseudo-static page, the rule is as follows: Rewriteengine on Rewriterule ([A-za-z]{1,})-([0-9]{1,}). html$index.php?action=$1&id=$2 In a regular expression, ([A-za-z]{1,})-([0-9]{1,}). html$ is the rule, the index.php?action=$1&id=$2 is the format to be replaced, the value that represents the 1th bracket match, and the value of the second parenthesis. So analogy!

Test the PHP script as follows: The code in the index.php file is as follows: Echo ' Your Action value is: '. $_get[' action ']; Echo '; The echo ' ID value is: '. $_get[' id '];?>

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

Oh, rewrite success!

Article Source: http://jingyan.baidu.com/article/624e7459aa58e434e8ba5ac2.html

PHP open pseudo-static configuration

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.