. Htaccess syntax parameter description

Source: Internet
Author: User
Tags php source code set cookie

Friends who have been familiar with the. htaccess file do not understand some of the opposite syntaxes. I often see a rule followed by some capitalized L NC R QSA or something. Do you know what they mean? OK. The following article briefly describes the syntax PARAMETERS OF THE. htaccess file.

Chain | C (link to the next rule)

This flag links the current rule to the next rule. It produces the following effect: if a rule is matched, the subsequent rule is processed, that is, the tag does not work. If the rule is not matched, the subsequent rules are skipped. For example, when executing an external redirection in a directory-level rule, you may need to delete ". www" (". www" should not appear here ").

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

Set a cookie on the client. The cookie NAME is NAME and the value is VAL. Domain is the domain of the cookie, such as .apache.org. The optional life time is the cookie's validity period (in minutes), and the optional path is the cookie's path.

Env | E = VAR: VAL (set environment variables)

This flag sets the environment variable VAR value to VAL, which can contain extensible Regular Expressions for reverse reference ($ N and % N ). This tag can be used multiple times to set multiple variables. These variables can be indirectly referenced in many cases, usually in XSSI (<! -# Echo var = "VAR"->) or CGI ($ ENV {VAR}), you can also use % {env in the CondPattern parameter of the subsequent RewriteCond command: VAR} references. You can use it to remember the information stripped from the URL.

Forbidden | F (forcibly disable URL)

The current URL is forcibly forbidden, that is, an HTTP response code 403 (Forbidden) is immediately reported ). With this tag, you can link several RewriteConds to block certain URLs with conditions.

Gone | G (forcibly deprecated URL)

Force the current URL to be obsolete, that is, an HTTP response code 410 (obsolete) is immediately reported ). Use this tag to indicate that the page has been deprecated and does not exist.

Handler | H = Content-handler (force specified Content processor)

The Content processor of the target file is Content-handler. For example, it is used to simulate the ScriptAlias command of The mod_alias module to force all files in the ing 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 flag is used to prevent a URL that has been rewritten from being overwritten by a subsequent rule. For example, you can use it to rewrite the root path URL (/) to an existing URL (for example,/e/www /).

Next | N (start from scratch)

Re-execute the rewrite operation (starting from the first rule ). At this time, the URL processed again is not the original URL, but the URL processed by the last rewrite rule. It corresponds to the next command in Perl or the continue command in C language. This flag allows you to re-start the rewrite operation (immediately return to the beginning of the loop ). But be careful not to create an endless loop!

Nocase | NC (Case Insensitive)

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

Noescape | NE (do not escape the URI in the output)

This flag prevents mod_rewrite from applying regular URI escape rules to rewrite results. In general, special characters (%, $,;, etc.) are escaped as equivalent hexadecimal encoding (% 25', % 24', % 3B, etc ). This mark can prevent such escaping to allow symbols such as percent signs to appear in the output, for example:

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

Nosubreq | NS (internal subrequests are not processed)

When the current request is an internal subrequest, this flag forces the rewrite engine to skip this rewrite rule. For example, when mod_include tries to search for the default directory file (index. xxx), Apache will generate a subrequest internally. For a subrequest, the rewrite rule is not necessarily useful. If the entire rule set takes effect, it may even cause an error. Therefore, you can use this tag to exclude certain rules. Usage principle: if you add a CGI script prefix to the URL to force them to be processed by the CGI script, but the error rate (or resource overhead) of the sub-request processing is very high, in this case, you can use this tag.

Proxy | P (forced as a proxy)

This flag forces the replacement component internally to be sent as a proxy request, and immediately interrupts the rewrite processing, and then transfers the processing to the mod_proxy module. You must ensure that this replacement string is a valid URI that can be processed by mod_proxy (for example, starting with a http://www.phpernote.com), otherwise an error will be returned by a proxy module. Using this tag, you can map some remote components to the domain name space of the local server, thus enhancing the ProxyPass command function. Note: To use this function, you must have enabled the mod_proxy module.

Passthrough | PT (handed over to the next processor)

The Force rewrite engine sets the uri field in the internal request_rec structure as the value of the filename field. This small modification allows the output of the RewriteRule command to be (converted from URI to file name) Alias, scriptAlias, Redirect and other commands for subsequent processing [Original: 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.].

For example, 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 uri =/abc /... Rewrite to filename =/def /... But the subsequent mod_alias attempts to convert the URI to the file name will fail. Note: If you need to use multiple modules to convert URIs to file names, you must use this tag .. The mixed use of mod_alias and mod_rewrite is a typical example.

Qsappend | QSA (append query string)

This flag forces the rewrite engine to append a query string to an existing replacement string, instead of simply replacing it. If you need to add information to the request string by using the rewrite rule, you can use this flag.

Redirect | R [= code] (Force redirect)

If the Substitution starts with http: // thishost [: thisport]/(to make the new URL a URI), an external redirection can be executed forcibly. If no code is specified, an HTTP response code 302 (temporary movement) is generated ). To use other response codes in the range of-, you only need to specify them here (or use one of the following symbol names: temp (default), permanent, seeother ). The canonicalized URL can be fed back to the client, for example "/~" Rewrite it to "/u/", or always add a slash to/u/user, and so on.

Note: When using this tag, make sure that the field to be replaced is a valid URL. Otherwise, it will point to an invalid location! Remember that this flag only adds the http: // thishost [: thisport]/prefix to the URL, and the rewrite operation will continue. Generally, if you want to stop the rewrite operation and redirect immediately, you also need to use the L mark.

Skip | S = num (skip the successor rule)

This flag forces the rewrite engine to skip the num Rules after the current matching rule. It can simulate the if-then-else structure: the last rule is the then clause, And the skipped skip = N rules are the else clause. Note: It is different from the chain | C mark!

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

The MIME type of the target file is forced to be MIME-type, which can be used to forcibly set the content type based on certain conditions. For example, the following command enables the. PHP file to be displayed by mod_php according to the php source code MIME type (application/x-httpd-PHP-source) when the. php file is 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 images in a directory of anti-leech
  • Usage of several keywords such as $ this, static, final, const, and self in php
  • Disable the list directory using. htaccess
  • Fatal error Class 'soapclient' not found in... troubleshooting method
  • Php prompts Maximum execution time of 30 seconds exceeded... solution to the error
  • 10 practical. htaccess code snippets
  • Using. htaccess to deny access to a website from an ip address

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.