Php+apache implement URL pseudo-static, Phpapache pseudo static _php tutorial

Source: Internet
Author: User

Php+apache implement URL pseudo-static, Phpapache pseudo-static


Apache Mod_rewrite is relatively strong, in the construction of the site, you can use this module to achieve pseudo-static.

The main steps are as follows:

1. Detect if Apache is turned on mod_rewrite function you can view the environment configuration through PHP's Phpinfo () function and find "Loaded Modules", which lists all the modules that have been opened by Apache2handler, if included " 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 you create a new. htaccess file, write the following in it: Rewriteengine on #rewriteengine为重写引擎开关on为开启off为关闭 rewriterule ([0-9]{1,}) $index. php?id=$1 here, Rewriterule is a rewrite rule, which is a sentence with regular expressions, ([0-9]{1,}) that is represented by numbers, $ represents the end flag, and ends with a 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!

Here are some personal experiences of my own pseudo-static configuration to share:

Start to contact pseudo-static, looking very magical, it is very difficult, in fact, is very simple, is in the server more than a few virtual domain names, similar to the real access URLs. Only three steps

A. First in Apache Apache module, open Vhost_alias_moudle

B. Modify the httpd.conf file, and in this file, search for rewrite. Find LoadModule rewrite_module modules/mod_rewrite.so remove the front #

C. Modify this file, the httpd-vhosts.conf file under Path D:\wamp\bin\apache\Apache2.2.21\conf\extra, follow the example and add one to OK.

Copy the Code code as follows:

ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "D:/wamp/www/dz"
ServerName localhost.www.dz.cn
Errorlog "Logs/dummy-host2.example.com-error.log"
Customlog "Logs/dummy-host2.example.com-access.log" common

D. Configure it in the Hosts file under Path C:\Windows\System32\drivers\etc

127.0.0.1 localhost.www.dz.cn Restart the service. Done!

Happy New Year to everyone!

Note: In the browser input localhost.www.dz.cn, can be accessed, I add a localhost is to and official web site to distinguish. Have not understood can contact me, convenient everybody to discuss together, common progress!

Your pseudo-static rules are all written in the. htaccess file, and the file is loaded by default because pseudo-static is turned on. Write this. htaccess file to write a regular. Oh, learn some regular basics!

http://www.bkjia.com/PHPjc/959110.html www.bkjia.com true http://www.bkjia.com/PHPjc/959110.html techarticle Php+apache implementation of pseudo-static URL, phpapache pseudo-static Apache Mod_rewrite is relatively powerful, in the construction of the site, you can use this module to achieve pseudo-static. The main steps are as follows ...

  • 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.