Create and Manage Domains

Quick Samples

Domain names only include the domain and the top level domain extension (TLD).

example.com

The sub-domain names include a period, you must make sure to include the period!

required host = "www\.";

You can define a sub-domain replacement using the website() function:

required host = website("(w{1,4}\.|)", "www");

This means use "www" if you find nothing, "w", "ww", "www", or "wwww".

A sub-domain that is an option is marked as a flag:

required language = flag("(en|fr)\.", "en");

Entries can either be required or optional. For example, the language could be made optional in this way:

optional language = flag("(en|fr)\.");

Note that optional entries do not take a default.

The period in a sub-domain is required in the following example because it uses two definitions that are both required to define a complete sub-domain:

required part1 = "(test|debug|release)-";
required part2 = "server\.";

In this case the sub-domain is one of: test-server, debug-server, or release-server.

Explanations

Once you start Snap Manager and successfully connect to Cassandra, you get the ability to go to the Domains tab. That tab gives you the ability to create and manage the domains that your Snap installation manages.

The New button creates a new domain. Enter the domain name at the top and at least one set of rules. The domain name must be just that, no sub-domains are allowed.

Examples of valid domain names:

example.com
example.info
example.net
example.co.uk
example.co.at

Note: We use the libtld to determine the TLD of your domain name. If it doesn't match any TLD or if you have more than two periods to the left, then you get an error about your domain name not being legal here.

The rules are defined using a simple language. The language allows you to define rules on a per website basis. So each rule set defines "one website" (in reality even one rule set at this level can declare multiple websites since you can use dynamic rules.)

The low level details about the rules are defined on the URL Test page. As you will see, in a way it is very similar to what Apache does with Virtual Hosts. Only, in our case we can define multiple websites with a single rule set and we don't have to define each and every parameter for each website as they all work in a similar way.

To start with, we'll use a simple example. Say you have a website at www.example.com. You want to enter a rule as follow:

my_site {
  required host = "www";
};

This is enough to create a website that responds to "http://www.example.com/".

Now a days, it is very common to get websites that understand "www.example.com" or no sub-domain as in "example.com". In order to support such, you can use the following rule which is called a group:

my_site {
  optional host = website("www\.", "www");
};

The fact that it is optional allows for the special "" case. The "www" is the default. So if someone enters "http://example.com", Snap will send that person to "http://www.example.com" first with a 301 request.

The order in which the rules are entered is important as they are checked in that order only. If something doesn't match then the rule set is ignored and the next rule set is checked. The first rule set that matches in full is the one selected.

This means if a rule set matches everything, then all the following rule sets are ignored. In other words, you probably want to put the most constrained rule sets first.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly