Home >Backend Development >PHP Tutorial >.htaccess syntax parameter description_PHP tutorial

.htaccess syntax parameter description_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:30:53911browse

Friends who have been exposed to .htaccess files may not understand some of the syntax on the opposite side. You will often see a rule followed by some capital letters L NC R QSA or something like that. Do you know what they mean? OK, the following article is a brief explanation of the relevant syntax parameters of the .htaccess file.

chain|C (link next rule)

This tag links the current rule to the next rule. It has the effect that if a rule is matched, its successor rules will continue to be processed, that is, this tag will have no effect; if the rule is not matched, its successor rules will be skipped. For example, when performing an external redirect in a directory-level rule, you may need to remove ".www" (".www" should not appear here).

cookie|CO=NAME:VAL:domain[:lifetime[:path]](set cookie)

Set a cookie on the client side. The name of the cookie is NAME and the value is VAL. domain is the domain of the cookie, such as .apache.org, optional lifetime is the validity period of the cookie (minutes), and optional path is the path of the cookie.

env|E=VAR:VAL (set environment variable)

This tag sets the value of the environment variable VAR to VAL. VAL can contain expandable regular expression backreferences ($N and %N). This tag can be used multiple times to set multiple variables. These variables can be indirectly referenced in many subsequent situations, usually in XSSI () or CGI ($ENV{VAR}), or in subsequent RewriteCond Referenced through %{ENV:VAR} in the CondPattern parameter of the instruction. Use this to remember information stripped from the URL.

forbidden|F (forbidden URL)

Forcibly ban the current URL, that is, immediately feedback an HTTP response code 403 (forbidden). Using this tag, you can chain several RewriteConds to conditionally block certain URLs.

gone|G (forced abandonment of URL)

Forcing the current URL to be obsolete, that is, immediately feedback an HTTP response code 410 (obsolete). Use this tag to indicate that the page has been abandoned and no longer exists.

handler|H=Content-handler (mandatory content handler specification)

Strongly customize the content handler of the target file as Content-handler. For example, the ScriptAlias ​​directive is used to emulate the mod_alias module to force all files within the mapped folder to be processed by the "cgi-script" processor.

last|L (ending rule)

Stop the rewrite operation immediately and no other rewrite rules will be applied. It corresponds to the last command in Perl or the break command in C language. This tag is used to prevent the currently rewritten URL from being rewritten again by subsequent rules. For example, you can use it to rewrite the URL of the root path (/) to an actual URL (for example: /e/www/).

next|N(start over)

Re-execute the rewrite operation (starting over from the first rule). At this time, the URL processed again is no longer the original URL, but the URL processed by the last rewriting rule. It corresponds to the next command in Perl or the continue command in C language. This mark allows the rewrite operation to be restarted (immediately back to the beginning of the loop). But be careful not to create an infinite loop!

nocase|NC(ignore case)

It makes Pattern ignore case, that is, when Pattern matches the current URL, there is no difference between A-Z and a-z.

noescape|NE (Do not escape URIs in output)

This tag prevents mod_rewrite from applying normal URI escaping rules to the rewrite results. Under normal circumstances, special characters (%, $, ;, etc.) will be escaped to the equivalent hexadecimal encoding (%25′, %24′, %3B, etc.). This flag prevents such escaping to allow symbols such as percent signs to appear in the output, such as:

RewriteRule /foo/(.*) /bar?arg=P1%3d$1 [R,NE] can redirect /foo/zed to a safe request /bar?arg=P1=zed

nosubreq|NS (internal subrequests are not processed)

This tag forces the rewrite engine to skip the rewrite rule when the current request is an internal subrequest. For example, when mod_include attempts to search the directory default file (index.xxx), Apache will generate a subrequest internally. Rewriting rules is not necessarily useful for subrequests, and it may even throw an error if the entire ruleset is in effect. Therefore, you can use this tag to exclude certain rules. Usage principle: If you add a CGI script prefix to URLs to force them to be processed by CGI scripts, but the error rate (or resource overhead) of subrequest processing is high, in this case, you can use this tag.

proxy|P (forced to be a proxy)

This flag causes the replacement component to be internally forced to be sent as a proxy request, immediately interrupting rewrite processing and handing over processing to the mod_proxy module. You must ensure that this replacement string is a valid URI that can be processed by mod_proxy (such as starting with http://www.phpernote.com), otherwise you will get an error returned by the proxy module. Using this tag, certain remote components can be mapped to the local server domain name space, thereby enhancing the functionality of the ProxyPass directive. Note: To use this feature, the mod_proxy module must be enabled.

passthrough|PT (hand over to next processor)

This tag forces the rewrite engine to set the uri field in the internal request_rec structure to the value of the filename field. This small modification enables the output of the RewriteRule directive to be converted from URI to filename by Alias, ScriptAlias, Redirect Wait for instructions for post-processing [Original text: This flag is just a hack to enable post-processing of the output of RewriteRule directives, using Alias, ScriptAlias, Redirect, and other directives from various URI-to-filename translators.].

Give an example to illustrate its meaning: If you want to rewrite /abc to /def, and then use mod_alias to convert /def to /ghi, you can do this:

RewriteRule ^/abc(.*) /def$1 [PT]
Alias ​​/def /ghi

If the PT tag is omitted, although the part that rewrites uri=/abc/… to filename=/def/… works fine, subsequent mod_alias will encounter failures when trying to convert the URI to a file name. Note: This tag must be used if you need to mix multiple modules that convert URIs to file names. . Mixing mod_alias and mod_rewrite here is a typical example.

qsappend|QSA(append query string)

This tag forces the rewrite engine to append a query string to the existing replacement string instead of simply replacing it. You can use this tag if you need to add information to the request string through rewriting rules.

redirect|R [=code](force redirect)

If the Substitution starts with http://thishost[:thisport]/ (making the new URL a URI), an external redirect can be forced. If no code is specified, an HTTP response code 302 (Temporary Move) is generated. If you need to use another response code in the range 300-400, just specify it here (or use one of the following symbolic names: temp (default), permanent, seeother). Use it to feed back the normalized URL to the client, such as rewriting "/~" to "/u/", or always adding a slash to /u/user, etc.

Note: When using this tag, you must ensure that the replacement field is a valid URL. Otherwise, it would point to an invalid location! And remember that this tag itself just prefixes the URL with http://thishost[:thisport]/, the rewriting operation will still proceed. Usually, you will also want to stop the rewriting operation and redirect immediately, so you will also need to use the L flag.

skip|S=num (skip subsequent rules)

This tag forces the rewrite engine to skip num rules after the current matching rule. It can simulate an if-then-else structure: the last rule is a then clause, and the skip=N rules are else clauses. Note: It is different from the chain|C tag!

type|T=MIME-type (mandatory MIME type)

Forcing the MIME type of the target file to be MIME-type, which can be used to force the content type based on certain conditions. For example, the following command allows .php files to be displayed by mod_php according to the MIME type of the PHP source code (application/x-httpd-php-source) when called with the .phps extension:

RewriteRule ^(.+.php)s$ $1 [T=application/x-httpd-php-source]

Articles you may be interested in

  • phpMyAdmin Cannot start session without errors error solution
  • .htaccess How to set up anti-hotlinking for pictures in a directory
  • Usage of several keywords such as $this, static, final, const, self, etc. in php
  • Use .htaccess ban list directory
  • Fatal error Class 'SoapClient' not found in...Error handling method
  • php prompts Maximum execution time of 30 seconds exceeded... Solutions to errors
  • 10 practical .htaccess code snippets
  • Use .htaccess to deny certain IP access to the website

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764191.htmlTechArticleFriends who have been exposed to .htaccess files may not understand some of the syntax on the opposite side. You will often see a rule behind it. Do you know what the capital letters L NC R QSA and the like mean...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn