PHP Open Pseudo-static (Appserv server)

Source: Internet
Author: User

PHP Open Pseudo-static (Appserv server)

Date: 2014-02-11 published by: SHX Views: 968 Comments: 0

Mod_rewrite is a very powerful feature of Apache that can implement pseudo-static pages. Let me tell you more about how it's used.

1. Detect if Apache supports Mod_rewrite

The phpinfo () function provided by PHP looks at the environment configuration and finds the "Loaded Modules" through ctrl+f , which lists all the modules that have been opened by Apache2handler. If "mod_rewrite" is included, it is already supported and no further setup is required.

If "mod_rewrite" is not turned on, open the httpd.conf file under your Apache installation directory "/apache/conf/", and Ctrl+f find the " LoadModule rewrite_module", remove the previous"#"number.

If not found, go to the "LoadModule" area and add "LoadModule rewrite_module, modules/mod_rewrite.so" (a required exclusive row) on the last line. Then restart the Apache server.

2. Let Apache server support. htaccess

How do I get my local Apache server to support the ". htaccess"? In fact, simply modify the Apache httpd.conf settings to allow Apache support. htaccess. Open a. httpd.conf file (where?) Conf directory in the Apache directory),

Open a. httpd.conf file (where?) Conf directory in the Apache directory),

When opened with a text editor, find

Options FollowSymLinks

AllowOverride None

Switch

Options FollowSymLinks

AllowOverride All

You can do it.

3. Create a. htaccess file

There are 1 easiest ways to build. htaccess files:

Open with Notepad, click File – Save As, enter ". htaccess" in the File name window, notice the whole green section,

That is, include the quotation marks, and then click Save on the line.

4.rewrite Rule Learning

After we create a new . htaccess file, we write the following in it:

rewriteengine on #rewriteengine for override engine switch on to on off for off

Rewriterule ([0-9]{1,}) $index. php?id=$1

Let me explain. Rewriterule:rewriterule is a rewrite rule that supports regular expressions, above ([0-9]{1,}) refers to the number of

The word composition, $ is the end of the flag, the description is ending with a number!

OK, now we can implement pseudo-static page, write down the following rules:

Rewriteengine on

Rewriterule ([A-za-z]{1,})-([0-9]{1,}). html$index.php?action=$1&id=$2

([A-za-z]{1,})-([0-9]{1,}). html$ is the rule, and index.php?action=$1&id=$2 is the format to be replaced, representing the first

A pair of parentheses matches the value, which is the second one, so to speak!!

We write a PHP script for processing:

index.php

PHP code

123456 <?phpecho‘你的Action是:’ . $_GET[‘action‘];echo ‘’;echo‘你的ID是:’ . $_GET[‘id‘];?>

OK, now we're typing in the browser:

Localhost/page-18.html

The output is:

Your action is: page

Your ID is: 18

published

PHP Open Pseudo-static (Appserv server)

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.