The Apache Rewrite URL redirection feature simple configuration _linux

Source: Internet
Author: User
Tags modifier
Main functions of 1.Apache rewrite
is to implement the URL of the jump and hide the real address, based on the Perl language regular expression specification. Usually help us achieve quasi static, quasi-directory, domain name jump, prevent hotlinking, etc.

configuration of 2.Apache rewrite
Apache rewrite configuration has two main, one is for the entire Apache server configuration, the rewrite rules of this configuration is directly written under httpd.conf. The configuration steps are as follows:
(1) Remove the "#" number in front of "#LoadModule rewrite_module modules/mod_rewrite.so" in the httpd.conf file;
(2) and then write the following rules in httpd.conf:
Rewriteengine on
#当访问任何以t_开头, when a file ending with. html is replaced with a character that matches (. *), the corresponding test.php page is accessed
Rewriterule ^/t_ (. *). html$/test.php?id=$1

The other is for the configuration of a directory under the Apache server, and the rewrite rules for this configuration need to be set up in this directory to write a. htaccess file. The configuration steps are as follows:
(1) Remove the "#" number in front of "#LoadModule rewrite_module modules/mod_rewrite.so" in the httpd.conf file;
(2) Modify the "AllowOverride None" in the httpd.conf file as "allowoverride all", at the same time, it is best to make the options also "all", otherwise there may be problems.
(3) Create a. htaccess file in the directory and open it with Notepad to write the following rules:
Rewriteengine on
Rewriterule ^/t_ (. *). html$/test.php?id=$1

the writing of 3.Apache rewrite rules
Rewriteengine on
Rewriterule ^/test ([0-9]*). html$/test.php?id=$1
Rewriterule ^/new ([0-9]*)/$/new.php?id=$1 [R]

Rewriteengine on
#当我们访问的地址不是以www. 163.com, then execute the next rule
Rewritecond%{http_host}!^www.163.com [NC]
Rewriterule ^/(. *) http://www.163.com/[L]

4.Apache rewrite rule modifier
1) R Force external redirection
2) F disables the URL and returns a 403HTTP status code.
3 G force URL to gone, return 410HTTP status code.
4) P enforces the use of proxy forwarding.
5) L indicates that the current rule is the last rule, and the rewrite of the rule is stopped after parsing.
6) N rerun the rewrite process starting with the first rule.
7) C is associated with the next rule

If the rule match is handled correctly, the following modifier is not valid

8 T=mime-type (Force MIME type) force MIME type
9 NS only for not internal child requests
NC is case insensitive
One) QSA Append request string
NE does not output escape special characters \%3d$1 equivalent to =$1

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.