Apache Rewrite common settings instructions

Source: Internet
Author: User
Tags deprecated response code

 Example: Rewriteengine on open engine rewriterule test.html/test.php [L] rewriterule test.html?$/tianqi.php?s1=& Amp;s2=&s3 = [qsa,l] for multiple parameters rewriterule tianqi-([0-9]+). html/tianqi.php?id=$1 [L]Note the problem with the path. Text:. matches any single character [chars] matches the current character [^chars] does not match the current character text1|text2 contains Text1 or text2 any one quantifiers:? 0 or one of the characters before the number * 0 or any arbitrary length of any character one or any arbitrary length of characters anchors:^ matches the start tag $ match content end tag Escaping:char used to escape special characters, including ". Escape of characters such as [] () "Flags ' redirect| R [=code] ' (forced redirection redirect)A substitution that is prefixed with http://thishost[:thisport]/(making the new URL a URI) can be forced to perform an external redirect. If code is not specified, an HTTP response code of 302 (temporary move) is generated. If you need to use a different response code in the range of 300-400, you can specify this value here, plus one of the following symbol names: Temp (default), permanent, seeother. It can be used to feedback the normalized URL to the client, such as, "/~" to "/u/", or/u/user plus slashes, and so on. Note: When using this tag, you must ensure that the replacement field is a valid url! Otherwise, it will point to an invalid location! And keep in mind that this tag itself is just a prefix to the URL plus http://thishost[:thisport]/, and the rewrite operation will still continue. In general, you will want to stop the rewrite operation and immediately redirect, then you also need to use the ' L ' tag.' forbidden| F ' (force URL for forbidden Forbidden)Forces the current URL to be disabled, that is, immediately feedback an HTTP response code of 403 (forbidden). With this tag, you can link several rewriteconds to conditionally block certain URLs.' gone| G ' (force URL to obsolete gone)Forces the current URL to be obsolete, that is, immediately feedback an HTTP response code 410 (deprecated). Using this tag, you can indicate that the page has been deprecated and does not exist.' proxy| P ' (Force agent proxy)This flag causes the replacement ingredient to be internally coerced to the proxy request and immediately (that is, the rewrite rule handles immediate interrupts) handing over the processing to the proxy module. You must make sure that this replacement string is a valid URI (such as a common one that starts with http://hostname) that can be handled by the Apache proxy module. With this tag, some remote components can be mapped to the local server namespace, thereby enhancing the functionality of the Proxypass directive. Note: To use this feature, the proxy module must be compiled on the Apache server. If you are not sure, you can check if the output of ' httpd-l ' is mod_proxy.c. If so, mod_rewrite can use this feature, and if not, you must enable MOD_PROXY and recompile the ' httpd ' program.' last| L ' (Final Rule last)Stops the rewrite operation immediately and no longer applies another rewrite rule. It corresponds to the last command in Perl or the break command in the C language. This tag prevents the currently overridden URL from being overridden by its successor rule. For example, use it to rewrite the URL of the root path ('/') to a URL that actually exists, for example, '/e/www/'.' next| N ' (re-execute next round)Re-executes the rewrite operation (starting with the first rule). The URL that was processed again is not the original URL, but the URL that was processed by the last rewrite rule. It corresponds to the next command in Perl or the Continue command in the C language. This tag can restart the rewrite operation, that is, immediately return to the head of the loop. But be careful not to create a dead loop!' chain| C ' (link to next rule chained)This tag causes the current rule to be linked to the next rule (which itself can be linked to its successor rule and can be so repeated). It produces such an effect: if a rule is matched, it will usually continue to process its successor, that is, the tag does not work, and if the rule cannot be matched, then its subsequent linked rules are ignored. For example, when performing an external redirect, for a directory-level rule set, you may need to delete ". www" (where ". www" should not appear).' type| T=mime-type ' (force MIME type types)The mandatory MIME type for the target file is Mime-type. For example, it can be used to simulate the Scriptalias directive in Mod_alias to internally force the MIME type of all files in the mapped directory to be ' application/x-httpd-cgi '.' nosubreq| NS ' (only for no internal sub-request processing no internal sub-request)This token forces the rewrite engine to skip the rewrite rule when the current request is an internal child request. For example, when Mod_include tries to search for possible directory default files (index.xxx), Apache generates child requests internally. A child request, which is not necessarily useful, and may even throw an error if the entire ruleset is working. Therefore, you can use this tag to exclude certain rules. Follow these guidelines according to your needs: If you use URL prefixes with CGI scripts to force them to be handled by CGI scripts, the error rate (or overhead) of processing a child request is high, in which case you can use this tag.' nocase| NC ' (ignoring case of uppercase and lowercase)It makes the pattern ignore case, that is, ' A-Z ' and ' A-Z ' are not different when pattern matches the current URL.' qsappend| QSA ' (Append request string query string append)This flag forces the rewrite engine to append a request string to an existing replacement string, rather than a simple replacement. You can use this tag if you need to add information to the request string through a rewrite rule.' Noescape|ne ' (no URI escaped in the output no URI escaping)This flag prevents Mod_rewrite from applying a general URI escape rule to the overridden result. In general, special characters (such as '% ', ' $ ', '; ') And so on) will be escaped to the equivalent hexadecimal encoding. This tag prevents such escapes to allow symbols such as percent sign to appear in the output, such as: rewriterule/foo/(. *)/bar?arg=p1\%3d$1 [R,ne] can turn '/foo/zed ' to a secure request '/bar?arg=p1= Zed '.' Passthrough|pt ' (handed over to the next processor pass through)This flag forces the rewrite engine to set the URI field in the internal structure Request_rec to the value of the FileName field, which is only a small modification to the Alias,scriptalias from other URIs to the file name translator Redirect The output of the command is subsequently processed. Give an example of what it means: if you want to rewrite/ABC as/def through the mod_rewrite rewrite engine, and then turn/def into/ghi by Mod_alias, you can: Rewriterule ^/abc (. *)/def$1 [PT] Alias/def/ghi if the PT tag is omitted, although mod_rewrite works fine, that is, as a URI to the file name translator using the API, it can rewrite the uri=/abc/... For filename=/def/..., however, subsequent mod_alias are invalidated when attempting to translate the URI to the file name. Note: You must use this tag if you need to mix a different module that contains a URI to the file name translator. Mixed use of Mod_alias and mod_rewrite is a typical example. For Apache hackers if the current Apache API, in addition to the URI to the file name hook, there is a file name to the file name of the hook, you do not need this tag! However, if there is no such a hook, then this tag is the only solution. Apache Group has discussed this issue and will add such a hook in Apache version 2.0.' skip| S=num ' (Skip the successor rule skip)This flag forces the rewrite engine to skip the NUM rules succeeding the current matching rule. It can implement a pseudo-If-then-else construct: The last rule is the then clause, and the skip=n rule that is skipped is the ELSE clause. (IT and ' chain| The C ' tag is different!)' env| E=var:val ' (Set environment variable environment variable)This flag causes the value of the environment variable VAR to be Val, and Val can contain an extensible inverse reference to the regular expression $n and%n. This tag can be used multiple times to set multiple variables. These variables can be referenced indirectly in many subsequent cases, but usually in Xssi (via or CGI (e.g. $ENV {' VAR '}), or by%{env:var} in the pattern of subsequent rewritecond instructions. Use it to peel and remember some information from the URL.' cookie|co=name:val:domain[:lifetime[:p Ath]] ' (Set cookies)It sets a cookie on the client browser. The name of the cookie is "name" and its value is Val. The Domain field is the field of the cookie, such as '. Apache.org ', the optional lifetime is the number of minutes of the cookie's lifetime, and the optional path is the cookie. Attached: Path_info read URL method: Test.php/s1/2/s2/3if (!empty ($_server[' path_info ')) {$paths = explode ('/', substr ($_server[')     Path_info '], 1)); for ($i = 0, $cnt = count ($paths); $i<$cnt; $i + +) {$_request[$paths [$i]]= $paths [+ + $i]; }     }

Apache Rewrite common settings instructions

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.