Apache's Rewrite rules are detailed

Source: Internet
Author: User

Rewrite logo:

R[=code] (Force redirect) forced External redirect F (forces URL to is forbidden) disable URL, return 403HTTP status code g (Force URL to is gone) mandatory URL is gone, return 410HTT P Status Code p (Force proxy) enforces the use of proxy forwarding L (last rule) to indicate that the current rule is the final rule, stop parsing after the rule's rewrite N (next round) re-run from the first rule to start the rewrite process C (chained with next rule ) is associated with the next rule, if the rule match is handled normally, the flag is not valid, and if it does not match, all of the following associated rules are skipped T=mime-type (Force MIME type) forcing MIME type NS (used only if no internal Sub-request) is used only for internal sub-request NC (no case) QSA (query string append) Append request string NE (no URI escaping of output) no longer outputs escaped special characters such as: Rewri terule/foo/(. *)/bar?arg=p1\%3d$1 [R,ne] will be able to convert/foo/zoo to/BAR?ARG=P1=ZEDPT correctly (pass through to next handler) Passed to the next processing example: Rewriterule ^/abc (. *)/def$1 [PT] # will be handed over to/def rule processing alias/def/ghis=num (skip next rule (s)) skipping NUM rule e=var:val (set environment variable) setting environment variables

Rewrite Server variables:

HTTP headers:http_user_agent, Http_referer, Http_cookie, Http_host, Http_acceptconnection & Request:remote_addr, Query_stringserver Internals:document_root, Server_port, Server_protocolsystem stuff:time_year, TIME_MON, TIME_DAY

Description of the rewrite rule expression:

<<= 9) Reverse Reference%N for the last matching variable call in Rewritecond (1 <<  = 9)

Rewritecond Marker:

' Nocase| NC ' (no case) ignores size ' ornext|or ' (or Next condition) logic or, can match multiple rewritecond conditions simultaneously

Rewriterule Applicable markers:

' Redirect| R [=code] ' (force redirect) forced rewrite for an external turn based on HTTP (note URL changes) such as: [R=301,l] ' forbidden| F ' (Force URL to is forbidden) rewritten as forbidden to access ' proxy| P ' (force proxy) overrides the HTTP path that is accessed through the proxy ' last| L ' (last rule) The final rewrite rule flag, if matched, no longer executes the subsequent rule ' next| N ' (next round) loops the same rule until the match is not met ' chain| C ' (chained with next rule) if the rule is matched, continue with the following rules with the chain flag. ' Type| T=mime-type ' (Force MIME type) specifies the MIME type ' nosubreq| NS ' (used only if no internal sub-request) Skip ' nocase| if it is an internal sub-request NC ' (no case) ignore size ' qsappend| QSA ' (query string append) appends the query string ' Noescape|ne ' (no URI escaping of output) to prevent characters in the URL from automatically escaping into%[0-9]+ form. ' Passthrough|pt ' (pass through to next handler) applies the rewrite results to Mod_alias ' skip| S=num ' (skip next rule (s)) skips the following few rules ' env| E=var:val ' (Set environment variable) Add environment variable

Actual operation

Example:

Rewriteengine Onrewritecond%{http_user_agent} ^msie [Nc,or]rewritecond%{http_user_agent} ^Opera [NC]RewriteRule ^.*- [F,l] Here "-" means no replacement, the browser for IE and opera visitors will be banned from accessing.

Restrict a catalog to display only pictures

Rewriteengine Onrewritecond%{request_filename}!^. (gif|jpg|jpeg|png|swf) $RewriteRule. $-[f,l]

Apache's Rewrite rules are detailed

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.