⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rewrite_intro.html.en

📁 Apache官方在今天放出产品系列2.2的最新版本2.2.11的源码包 最流行的HTTP服务器软件之一
💻 EN
📖 第 1 页 / 共 2 页
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX              This file is generated from xml source: DO NOT EDIT        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX      --><title>Apache mod_rewrite Introduction - Apache HTTP Server</title><link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /><link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /><link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link href="../images/favicon.ico" rel="shortcut icon" /></head><body id="manual-page"><div id="page-header"><p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p><p class="apache">Apache HTTP Server Version 2.2</p><img alt="" src="../images/feather.gif" /></div><div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div><div id="path"><a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.2</a> &gt; <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>Apache mod_rewrite Introduction</h1><div class="toplang"><p><span>Available Languages: </span><a href="../en/rewrite/rewrite_intro.html" title="English">&nbsp;en&nbsp;</a></p></div><p>This document supplements the <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code><a href="../mod/mod_rewrite.html">reference documentation</a>. Itdescribes the basic concepts necessary for use of<code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>. Other documents go into greater detail,but this doc should help the beginner get their feet wet.</p></div><div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#introduction">Introduction</a></li><li><img alt="" src="../images/down.gif" /> <a href="#regex">Regular Expressions</a></li><li><img alt="" src="../images/down.gif" /> <a href="#rewriterule">RewriteRule basics</a></li><li><img alt="" src="../images/down.gif" /> <a href="#flags">Rewrite Flags</a></li><li><img alt="" src="../images/down.gif" /> <a href="#rewritecond">Rewrite conditions</a></li><li><img alt="" src="../images/down.gif" /> <a href="#rewritemap">Rewrite maps</a></li><li><img alt="" src="../images/down.gif" /> <a href="#htaccess">.htaccess files</a></li></ul><h3>See also</h3><ul class="seealso"><li><a href="../mod/mod_rewrite.html">Moduledocumentation</a></li><li><a href="rewrite_tech.html">Technical details</a></li><li><a href="rewrite_guide.html">Practical solutions to commonproblems</a></li><li><a href="rewrite_guide_advanced.html">Practical solutions toadvanced problems</a></li></ul></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="introduction" id="introduction">Introduction</a></h2><p>The Apache module <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> is a very powerful andsophisticated module which provides a way to do URL manipulations. Withit, you can do nearly all types of URL rewriting that you may need. Itis, however, somewhat complex, and may be intimidating to the beginner.There is also a tendency to treat rewrite rules as magic incantation,using them without actually understanding what they do.</p><p>This document attempts to give sufficient background so that whatfollows is understood, rather than just copied blindly.</p><p>Remember that many common URL-manipulation tasks don't require thefull power and complexity of <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>. For simpletasks, see <code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code> and the documentationon <a href="../urlmapping.html">mapping URLs to thefilesystem</a>.</p><p>Finally, before proceeding, be sure to configurethe <code class="directive"><a href="../mod/mod_rewrite.html#rewritelog">RewriteLog</a></code>. Althoughthis log file can give an overwhelming amount of information, it isindispensable in debugging problems with <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>configuration, since it will tell you exactly how each rule isprocessed.</p></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="regex" id="regex">Regular Expressions</a></h2><p>mod_rewrite uses the <a href="http://pcre.org/">Perl CompatibleRegular Expression</a> vocabulary. In this document, we do not attemptto provide a detailed reference to regular expressions. For that, werecommend the <a href="http://pcre.org/pcre.txt">PCRE man pages</a>, the<a href="http://perldoc.perl.org/perlre.html">Perl regularexpression man page</a>, and <a href="http://www.oreilly.com/catalog/regex2/index.html">MasteringRegular Expressions, by Jeffrey Friedl</a>.</p><p>In this document, we attempt to provide enough of a regex vocabularyto get you started, without being overwhelming, in the hope that<code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>s will be scientificformulae, rather than magical incantations.</p><h3><a name="regexvocab" id="regexvocab">Regex vocabulary</a></h3><p>The following are the minimal building blocks you will need, in orderto write regular expressions and <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>s. They certainly do notrepresent a complete regular expression vocabulary, but they are a goodplace to start, and should help you read basic regular expressions, aswell as write your own.</p><table><tr><th>Character</th><th>Meaning</th><th>Example</th></tr><tr><td><code>.</code></td><td>Matches any singlecharacter</td><td><code>c.t</code> will match <code>cat</code>,<code>cot</code>, <code>cut</code>, etc.</td></tr><tr><td><code>+</code></td><td>Repeats the previous match one or moretimes</td><td><code>a+</code> matches <code>a</code>, <code>aa</code>, <code>aaa</code>, etc</td></tr><tr><td><code>*</code></td><td>Repeats the previous match zero or moretimes.</td><td><code>a*</code> matches all the same things<code>a+</code> matches, but will also match an empty string.</td></tr><tr><td><code>?</code></td><td>Makes the match optional.</td><td><code>colou?r</code> will match <code>color</code> and <code>colour</code>.</td></tr><tr><td><code>^</code></td><td>Called an anchor, matches the beginningof the string</td><td><code>^a</code> matches a string that begins with<code>a</code></td></tr><tr><td><code>$</code></td><td>The other anchor, this matches the end ofthe string.</td><td><code>a$</code> matches a string that ends with<code>a</code>.</td></tr><tr><td><code>( )</code></td><td>Groups several characters into a singleunit, and captures a match for use in a backreference.</td><td><code>(ab)+</code> matches <code>ababab</code> - that is, the <code>+</code> applies to the group.For more on backreferences see <a href="#InternalBackRefs">below</a>.</td></tr><tr><td><code>[ ]</code></td><td>A character class - matches one of thecharacters</td><td><code>c[uoa]t</code> matches <code>cut</code>,<code>cot</code> or <code>cat</code>.</td></tr><tr><td><code>[^ ]</code></td><td>Negative character class - matches any character not specified</td><td><code>c[^/]t</code> matches <code>cat</code> or <code>c=t</code> but not <code>c/t</code></td></tr></table><p>In <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> the <code>!</code> character can beused before a regular expression to negate it. This is, a string willbe considered to have matched only if it does not match the rest ofthe expression.</p><h3><a name="InternalBackRefs" id="InternalBackRefs">Regex Back-Reference Availability</a></h3>      <p>One important thing here has to be remembered: Whenever you      use parentheses in <em>Pattern</em> or in one of the      <em>CondPattern</em>, back-references are internally created      which can be used with the strings <code>$N</code> and      <code>%N</code> (see below). These are available for creating      the strings <em>Substitution</em> and <em>TestString</em>.      Figure 2 shows to which locations the back-references are      transferred for expansion.</p><p class="figure">      <img src="../images/mod_rewrite_fig2.gif" width="381" height="179" alt="[Needs graphics capability to display]" /><br />      <dfn>Figure 2:</dfn> The back-reference flow through a rule.</p></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="rewriterule" id="rewriterule">RewriteRule basics</a></h2><p>A <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> consistsof three arguments separated by spaces. The arguments are</p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -