Sina SAE under Riwrite rewrite rules detailed

Source: Internet
Author: User

AppConfig module on-line, rewrite and compression page functions can be used
    • 03/19. 2010

What can appconfig do?

The AppConfig module is responsible for providing the user's ability to customize the Web server configuration, and features that are currently self-configurable include

    • Catalog default page

    • Custom error page

    • Compression

    • Page redirection

    • Page expires

    • Set the Content-type of the response header

Where do I set the AppConfig option?

In each version of the directory below, there is a file called Config.yaml, only need to append the Handel segment (green section), appconfig the use of YAML-based custom syntax.
Here is an example from sinat.sinaapp.com:

Name:sinat version:1 Handle:-Rewrite:if (!is_dir () &&!is_file ()) goto "Index.php?%{query_string}" #这里开头有两个空格

1

2

3

4

name : Sinat

version : 1

Handle :

- rewrite: if (! Is_dir () && ! Is_file ()) goto "index.php?%{query_string}" #这里开头有两个空格

In particular, it is important to note that the preceding space in Yaml cannot be replaced with a tab, otherwise it will prompt a syntax error.

Syntax description

AppConfig syntax is divided into two types, one is a simple parameter list, one is flexible expression syntax, different functions will use different types of syntax.

Parameter mode Catalog Default page

-Directoryindex:file_list
Each file name in the file_list is separated by a space, and DirectoryIndex has only one item in the Yaml file

Example:
-Directoryindex:aaa.php bbb.html

Custom error page

-Errordoc:httpcode Error_file
Httpcode is an HTTP response code such as 404,302, and Error_file is the file that the server responds to when the Httpcode responds to the request. Errordoc can configure multiple items in Yaml.
-Errordoc:404/path/404.html
-Errordoc:403/path/403.html

Expression syntax

Other features require expression syntax. In the form of:

if (expression) do_something

Expression has the following form

    • in_header["Header_name"] op string_or_digit

    • out_header["Header_name"] op string_or_digit

    • Path OP string

    • Query_string op string

    • Is_file ()

    • Is_dir ()

The above forms are described as follows:

    • In_header is the name of the header whose request Header,out_header is the response header,header_name

    • OP is operator, has ~ (regular match)!~ (regular mismatch) = = (equal, for string and number)! = (unequal, for strings and numbers) > >= < <= (comparison operators are only used for shaping numbers)

    • String is a character type such as "XXXX"

    • String_or_digit represents a string or digit, depending on the type of OP, followed by a string or digit

    • Path is a system macro that indicates that the URL of the user request is stripped of the host part and the remaining parts of the query string

    • Query_string is a system macro that represents a query string

    • Is_file () and Is_dir are system functions that determine if path is a file or directory,!is_file (), and!is_dir () are their negative forms.

Expression syntax is used for the following functions.

Compression

-Compress:if (single_express) Compress
Single_express represents a single expression in compress, cannot be combined with &&, In_header,out_header,path can appear in single_express

For example:
-Compress:if (out_header["Conteng-length"] >=) compress
-Compress:if (in_header["Referer"] = = "Gphone") compress
-Compress:if (path ~ "/big/") compress

URL rewriting

-Rewrite:if (complex_express) goto Target_url

In rewrite, complex_express can be used to form composite expressions with && connections. In addition to Out_header (no way to redirect based on the response header) can appear in the rewrite if, and path can only appear one (if there are multiple, only the last one to take effect, others are ignored), when omitting path, represents any request.
Target_url represents the destination URL of the redirect, where Target_url can represent the match to the path in the form of a $N,%N represents the match in the last query_string, because query_string can appear multiple times in the IF ,%{query_string} indicates a query string.

For example:
-Rewrite:if (query_string ~ "^ (so) $" && path ~ "zhaochou$") goto "/url/%1″
-Rewrite:if (Is_dir () && Path ~ "urldir/(. *)") goto "/url/$1″
-Rewrite:if (!is_file () &&!is_dir ()) goto "Index.php?%{query_string}"

Specify expiration time and header information

-Expire:if (single_express) Time seconds
-Mime:if (single_express) type Content-type
In expire and mime, single_express represents a single expression, cannot be used && compound, In_header,path can appear in Single_express, and op can only be ~ or = =, that is, only support the positive Then match and string comparison
Seconds is the number of seconds, and Content-type is a string representing the document type.

For example:
-Expire:if (in_header["referer"] ~ "Sina") time 10
-Mime:if (path ~ "\.pdf2$") type "Application/pdf"

More examples

For the convenience of everyone to use, Zhiyong classmate has been used for everyone to write a demonstration of grammar.

Catalog default page

Returns aaa.php when the access URL does not specify a file, or returns bbb.html if it does not exist

-Directoryindex:aaa.php bbb.html

Custom error page

Encountered a 404 error and returned a/path/404.html file. Encounter 403 error, return/path/404.html file

-Errordoc:404/path/404.html
-Errordoc:403/path/403.html

Compression

Compress when page content is greater than
-Compress:if (out_header["Conteng-length"] >=) compress

Compressed when the request header Content-type contains text
-Compress:if (out_header["Content-type"] ~ "text") compress

Compressed when the response header Referer equals Gphone
-Compress:if (in_header["Referer"] = = "Gphone") compress

Compressed when the requested URL contains "/big/"
-Compress:if (path ~ "/big/") compress

Note: For all compression, the request header accept-encoding contains gzip,deflate is the meaning of the title.

Page redirection

When the URL matches urldir/(. *) and the input header referer equals Sina, jumping to the page/usr/$1,$1 represents the (. *) part of the urldir/(. *) just matched.
-Rewrite:if (Path ~ "urldir/(. *)" && in_header["referer"] = = "Sina") goto "/url/$1″

When the URL matches urldir/(. *), and the request is a directory, jump to/url/$1
-Rewrite:if (Is_dir () && Path ~ "urldir/(. *)") goto "/url/$1″

Jumps to/url/query.php when the URL matches the path and the request is not a file
-Rewrite:if (! is_file () && Path ~ "path") goto "/url/query.php"

When the query string equals so, and the URL ends in Zhaochou, jumping to/url/%1,%1 represents the part to which query_string matches.
-Rewrite:if (query_string ~ "^ (so) $" && path ~ "zhaochou$") goto "/url/%1″

When the query string does not contain Sohu, and the URL ends in Zhaochou, jumping to/url/query.php?%{query_string},%{query_string} represents the query string.
-Rewrite:if (query_string!~ "Sohu" && Path ~ "zhaochou$") goto "/url/query.php?${query_string}"

If the URL is neither a file nor a directory, jump to index.php?%{query_string}
-Rewrite:if (!is_file () &&!is_dir ()) goto "Index.php?%{query_string}"

Set the MIME type of the response header

If the URL request file has a pdf2 extension, set Content-type to Application/pdf
-Mime:if (path ~ "\.pdf2$") type "Application/pdf"

As soon as the header Referer contains the string Sina, the Content-type is set to Text/plain
-Mime:if (in_header["referer"] ~ "Sina") type "Text/plain"

Page expires

If the request header Referer contains the string Sina, set the expiration time of 10s
-Expire:if (in_header["referer"] ~ "Sina") time 10

If the URL ends with Lib\.js, set the expiration time to 100s
-Expire:if (path ~ "lib\.js$") Time 100


Sina SAE under Riwrite rewrite rules 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.