Sina SAE URL rewrite (pseudo static, redirect) detailed

Source: Internet
Author: User
Tags goto password protection


Sina SAE URL rewrite (pseudo static, redirect) detailed http://www.veryhuo.comphpclubs2011-11-14deliver manuscript

SAE full Sina App Engine, is a good thing, he has a lot of excellent features, in short, SAE is a simple and efficient distributed Web services development, running platform.

Support now commonly used php+mysql environment, in the development will inevitably encounter projects need to do URL rewrite (pseudo-static), but SAE does not support Apache under the. htaccess. But don't be sad, SAE has provided its own rewrite way, this article we will introduce the SAE rewrite, hope that the comrades can quickly according to their own needs to write the desired rules

Config.yaml Introduction

The profile of the SAE is in the root directory of each application and the name is Config.yaml. This file is similar to the Apache. htaccess, where all pseudo-static rules, 404 settings, etc. are configured here.

Config.yaml content Format
Name:phpclubsversion:1handle:    -directoryindex:index.php index.html index.htm    -errordoc:404/path/404.html    -Rewrite:if (!is_dir () && Path ~ "urldir/(. *)") goto "/tools/$1"
Above is an application inside the Config.yaml file the first line indicates the name of the current application The second line represents the version of the currently applied code in the third line handle the following is the rule I want to write Config.yaml the way to change

When we create a project version, the system automatically generates the Config.yaml file in the root directory (if you do not have one manually created it), while we can edit the Config.yaml file via the online editor (SAE CLOUD Editor). On the other hand we can also use SVN local editor, submitted to the server, the changes are in real-time effect.

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

1. Expression syntax

The form is:

An if (expression) execution rule

An expression has the following form:

1) in_header["Header_name"] op string_or_digit

2) out_header["Header_name"] op string_or_digit

3) path OP string

4) query_string op string

5) Is_file ()

6) Is_dir ()

The above forms are described as follows:

1) In_header is the request header, Out_header is the response header, Header_name is the name of the header, which we generally use not much

2) OP is operator, has ~ (regular match)!~ (regular mismatch) = = (equal, used for strings and numbers)! = (unequal, used for strings and numbers);, >=, <, <= (comparison operators are used only for shaping numbers), where ~ regular matching uses more

3) string is a character type such as "XXXX"

4) String_or_digit means string or digit, depending on the type of OP, followed by a string or digit

5) path is a system macro, which means that the URL of the user request is removed from the host part and the remainder after the query string, for example: http://www.xxx.com/list/test.php?id=23 path is/list/test.php

6) Query_string is a system macro that represents a query string, usually the contents of a question mark in the URL, such as the id=23 in the URL above

7) Is_file () and Is_dir are system functions that determine whether the path is a file or a directory,!is_file (), and!is_dir () are their negative forms respectively. (More use also)

2. URL Rewriting

-rewrite:if (expression) goto destination URL

In rewrite, expressions can be combined with && to form composite expressions. Path can only appear one (if there are multiple, only the last one takes effect, others are ignored), and when path is omitted, any request is represented.

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}"

For example, we have to first pseudo-static below

Example 1

The real processing address is: www.xxx.com/index.php?a=list&b=new&id=23

To pseudo-static into this: www.xxx.com/list-new-23.html

Rule-rewrite:if (Path ~ "list-new-(\d+) \.html") goto "Index.php?a=list&b=new&id=$1″

Example 2

The real processing address is: www.xxx.com/index.php?a=list&b=new&id=23

To pseudo-static into this: www.xxx.com/list-new.php?id=23

Rule-rewrite:if (path ~ "list-new\.php" && query_string ~ "id= (\d+)") goto "Index.php?a=list&b=new&id=%1″

3. Custom Directory default page

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

–directoryindex:aaa.php bbb.html

4. Custom error page (404 pages, etc.)

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

5, the file directory for simple access rights authentication

Access to secret directory requires a password, allowing users to test with password 123qwe access, user coder with password 123ASD access

–passwdaccess:if (Path ~ "/secret/") passwd "Test:123qwe coder:123asd" access. Text ends with a password that allows the user writer to use the password 123ZXC–PASSW Daccess:if (Path ~ "\.text$") passwd "WRITER:123ZXC" All access to password, allowing the user writer with password 123zxc access –passwdaccess:passwd "Write:12 3zxc "User's website daemon is placed in the admin directory, need to do password protection to the Admin directory –passwdaccess:if (path ~"/admin/") passwd" Admin:admin123″ Tail language

Believe that you try to finish the above things, you should be able to write the rules you want. Good luck...

Also attached is a AppConfig configuration Generator tool http://saetools.sinaapp.com/This article refer to Sina SAE http://sae.sina.com.cn/?m=devcenter&catId=193
Source: >  

From for notes (Wiz)

Sina SAE URL rewrite (pseudo static, redirect) 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.