APACHE for PHP pseudo-static Rewrite settings-PHP source code

Source: Internet
Author: User
Tags perl regular expression
The main function of Rewirte is to redirect URLs and hide real addresses. it is based on Perl-based regular expressions. It usually helps us implement quasi-static, quasi-directory, domain name jump, prevent leeching and other Rewirte. The main function is to achieve URL jump and hide real addresses, based on the Perl Regular Expression specification. It usually helps us achieve quasi-static, quasi-directory, domain name jump, and prevent leeching.

1. Apache configuration:

1. support httpd. conf configuration
2. supports directory. htaccess configuration (a "distributed configuration" file is intended for virtual spaces, and the space provider does not allow Apache configuration files to be modified)

Enable Rewrite (httpd. conf)
(Sometimes Options Indexes FollowSymLinks has a problem. you only need to configure Options all)

LoadModule rewrite_module modules/mod_rewrite.so


Enable. htaccess
AllowOverride None: AllowOverride All

II. mod_rewrite rules:
For example:

RewriteEngine on-> start rewrite engine RewriteRule ^/test ([0-9] * mongo.html $/test. php? Id = $1-> testplus any field .html can jump to the test. php regex matching field stored in virtual memory matching $1

3. mod_rewrite rule modifier

1) R forces external redirection
2) F disables the URL and returns the 403HTTP status code.
3) if G forces the URL to be GONE, the response HTTP status code is returned.
4) P enforces proxy forwarding.
5) L indicates that the current rule is the last rule, and the rule is overwritten after analysis is stopped.
6) N re-run the rewrite process from the first rule.
7) C. associate with the next rule

If the rule matches, it is processed normally. the following modifier is invalid.

8) T = MIME-type (force MIME type) force MIME type
9) NS is only used for non-internal subrequests
10) the NC is case insensitive.
11) QSA append request string
12) NE does not output escape special characters \ % 3d $1 is equivalent to = $1
For example:

RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]

Simple example:

RewriteEngine onRewriteRule ^/in(.*).html$ /index.php

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.