EN / ZH
How to Bind a Domain to a Subdirectory on Sina SAE Cloud Platform

A while back, I introduced Sina’s Sina App Engine (Sina SAE Cloud Platform) service, which can be used to build free WordPress sites or deploy custom applications. I’ve also published posts like Scheduled SMS Notifications Based on Sina SAE Platform and Website Monitoring and Alert System Based on Sina SAE Platform. However, Sina SAE has a limitation: free users can only create up to 10 independent applications. Beyond that, you need to purchase a higher-tier account.

So here’s a handy trick: you can bind domains to subdirectories within a single application. For example, imzl.com is bound to the root directory of one application, while blog.imzl.com can be bound to that application’s /blog directory (both the domain and directory are customizable). This way, you can run multiple independent websites within a single application.

First, you need to bind your domain to the SAE application. There are two ways to bind a domain on SAE:

  1. If your domain already has ICP filing on another server, you can apply to SAE for domain binding: http://sae.sina.com.cn/?m=devcenter&catId=9

  2. Self-service binding. Open your application, go to “Application Settings,” and you’ll see the control panel under “Custom Domain Settings.” Follow the prompts step by step. (For domain binding details, see the article Sina SAE Opens Custom Domain Binding.)

After binding the domain, you need to write the Appconfig. The Appconfig is stored in the config.yaml file in the code directory. Here’s how to bind domains to subdirectories:

name: Sub-domain binding
handle:
- rewrite:if ( in_header["host"] ~ "blog.imzl.com" && path ~ "^(?!blog/)(.*)" ) goto "blog/$1?%{QUERY_STRING}"
- rewrite:if ( in_header["host"] ~ "code.imzl.com" && path ~ "^(?!code/)(.*)" ) goto "code/$1?%{QUERY_STRING}"
- rewrite:if ( in_header["host"] ~ "www.imzl.com"&& !is_file() &&path ~ "^(?!www/)(.*)" ) goto "www/$1?%{QUERY_STRING}"

Here’s what this code means:

blog.imzl.com is bound to the “/blog” directory
code.imzl.com is bound to the “/code” directory
www.imzl.com is bound to the “/www” directory

For instructions on installing applications in subdirectories, refer to SAE’s official documentation (it’s simply a matter of uploading files via SVN to the subdirectory you’ve designated).