NewsFeaturesDownloadsDevelopmentSupportAbout Us

Support for Subdomains

From LifeType Wiki

Contents

Introduction

LifeType 1.0 includes a very useful feature for sites wishing to offer blogging service: support for subdomains so that http://user1.domain.com would be a link to user1's blog, http://user2.domain.com would be a link to user2's blog and so on. This feature requires that wildcard domains are enabled for our domain so that *.domain.com is resolved to the same IP address, and to the same directory that your main domain points to. or in other words, there is no need to create the subdomains before they are used because when using wildcard subdomains, all possible host names will be resolved to the same address (and directory!)

Let's assume that you bought a domain called mydomain.com and that wildcard domains have been enabled for it. The first thing you should do to check whether support for subdomains is working is try to ping different host names under your subdomain even if they do not exist:

 ping whatever1.mydomain.com
 ping this.host.does.not.exist.mydomain.com
 ...

All these hosts should resolve to the same IP address.

Next, you should check what directory your subdomains are pointing to. You can either use a file from LifeType, or else make a test.html, and see if you can get to http://domain.com/test.html and http://user1.domain.com/test.html. If you cannot, you need to check with your host to see how to get subdomains pointing to the same directory as your main domain.

At this point, everything is ready. LifeType is smart enough to get the correct blog name from the host name so for example if the blog name is "Test blog", the URL will be "test_blog.mydomain.com" and LifeType knows how to extract such information because of the "subdomains_base_url" configuration parameter which should be set to "{blogname}.mydomain.com" (see below for more details)

How does it work?

LifeType supports redirection to blogs via subdomains in two different ways: via the blog name and via a username. So if the user 'john' owns the blog 'John's daily stories", then we can configure LifeType so that one of the following ways (and only one) is a valid link to John's blog: ~http://john.domain.com and ~http://johns_daily_stories.domain.com. If users are allowed to have more than one blog, the first one could be a problematic since LifeType will just show the first blog owned by the user. The second one will probably generate longer url-ized domain names but it might be the only solution if users are allowed to have more than one blog and we want them all to be accessible, as long as we don't have two blogs with the same name.

How to configure it

In order to enable support for subdomains, first of all we should log into the admin interface and in the Global Settings section, make sure that subdomains_enabled is set to Yes. Then, we have to define how our subdomain names should look like. The configuration of the format of the subdomains is controlled via the *subdomains_base_url* setting and there are two variable parameters that can be used to format our domain names:

Please keep in mind that only one of the variable parameters above can be used. Combinations such as http://{username}.{blogname}.domain.com are not allowed!

And keep also in mind that if subdomain_names is disabled, {username} and {blogname} will be literally displayed in urls generated internally by LifeType: they will not be translated!

Relationship between base_url and subdomains_base_url

  • base_url: this is the base URL used to generate links that do not need subdomains
  • subdmains_base_url: this is the base URL used to generate links that have subdomains, and it is only used when subdomains_enabled is set to true.

Both of these configuration parameters can be set to completely different things if needed.

Forbidden usernames

In order to avoid somebody to sign up as "www", "admin" or "ftp" (which would create quite weird blog URLs when subdomains are enabled suchas "www.mydomain.com" or "admin.mydomain.com", etc) the "forbidden_usernames" parameter can be used.

Reconfiguring our custom URLs to look nicer when subdomains are enabled

When custom URLs are enabled, by default they all include a {blogname} part so that LifeType knows which blog we are visiting. But when subdomains are enabled this information is a bit redundant because LifeType can already know the blog we're dealing with because of the hostname, so for example permalinks can be rewritten from

 /blog/{blogname}/{year}/{month}/{day}/{postname}$

to the following (as an example):

 /post/{year}/{month}/{day}/{postname}$

In other words, we can remove the "/blog/{blogname}" or "/blog/{blogowner}" part from each one of URL formats because it is not necessary anymore.

This should be repeated for every different URL that LifeType can generate. We should also make sure that .htaccess files are supported in our configuration (or else URLs like /post/ will not work)

Custom subdomains

Also known as hosted subdomains or multi domains, this is a feature available since LifeType 1.1 that allows one single installation to host several different domains. Instead of having a base subdomain and then several different blogs sharing the same subdomain (i.e. blog1.mydomain.com, blog2.domain.com, etc), it is now possible to configure LifeType to take care of www.domain1.com, www.domain2.com, and so on, with only one instance.

Blog owners are able to select their domain from a drop-down list. Additionally, this feature allows blog owners to type their preferred subdomain, instead of getting blog links that include either an URL-ized version of the blog name or the user name. The subdomain name will only be validated agains the list of forbidden usernames.

Configuration

There are multiple settings you need to get right in order to configuring hosted domains: DNS, Apache and LifeType. You should get your DNS configured (and tested) first, followed by Apache, followed by LifeType. IF you don't have the DNS configured and tested, it doesn't matter what your Apache or LifeType settings are. There are a couple possibilities for configuring hosted domains. For these examples, assume domain.com is where your main LifeType installation is.

1. You want your users to be able to pick blahblah.domain.com as their URL even though their username/blogname is not blahblah.
2. You want to host blogs.domain2.com, domain3.com, etc.
3. A combination of the above, where you want to have funnylooking.domain.com, domain3.com, and blog.domain2.com.

Decide which option you want to implement before continuing with the rest of the instructions.

DNS

I assume that you have a working LifeType installation, and you are trying to add hosted domains to your current, working installation. For option 1, it is just like regular subdomains, where you simply add an A or CNAME wildcard record in your DNS (*.domain.com). Your users won't have to do anything with DNS, but simply sign up for the blog. For option 2, you don't need to do anything with the DNS records, but your users will have to create a DNS record that points to your IP address (using an A record, and you would have to publish your IP address for them to use), or have them use a CNAME record that points to your LifeType installation, domain.com. For option 3, just follow the instructions for both 1 and 2.

Now, to test that you go the DNS correct, you should use an nslookup tool (search on the internet for a web-based one if you don't already have one). Type in your main LifeType installation's domain, and find out what your IP address is. Then, type in whatever domains you want to host with your LifeType installation: blahblah.domain.com, funnylooking.domain.com, domain3.com, blog.domain2.com, etc. They should all return the same IP address. Keep in mind that DNS records are cached, and depending on your provider, for long periods of time. DNSMadeEasy has excellent support and configuration options (Note, if you actually buy something from them using that link, Jon Daley gets a couple dollars for it, but I would recommend them even if I didn't -- they have tons of nameservers, the name resolves very quickly, and they let you set low TTLs (5 seconds). Since this documentation took a little under an hour to type, I don't think it is all that unreasonable to have a 'sponsored' link here). Once all of the domains are returning the correct IP address, it is time to move onto the Apache configuration.

Apache

This step has the most variation in it, since your host probably doesn't let you edit the httpd.conf file directly, but instead you have to use some GUI that hides the details from you and forces you to do different things. The simplest way to configure apache for hosted domains is to get a dedicated IP address for your LifeType installation, and then setup Apache to respond to all domains on that IP. I partially don't recommend this method, since it uses up an IP address, and the world is starting to run out of them. But, it does have its advantages. If you are using a non-dedicated IP address, you will have to configure Apache to respond to the domains you want to use. For option 1, you would need to setup a subdomain wildcard to point to the same directory as the main LifeType installation. For option 2, you will have to add the domain when your users sign up. Perhaps for that reason alone, a dedicated IP address is the right answer.

LifeType

In order to configure support for hosted domains in LifeType, the following parameters need to be configured:

  • subdomains_enabled = Yes
  • subdomains_base_url = {blogdomain}
  • subdomains_available_domains = (space-separated list of available

The most important setting is subdomains_available_domains, which must list all the domains that will be hosted by LifeType separated by a blank space. For option 1, simply enter domain.com. For option 2, enter a '?' as wildcard. The user is now allowed to set any valid domain in the blog settings. For option 3, put a ? followed by a blank space, followed by domain.com.

Using summary.php with subdomains

In casd you are using sudbomains and want to set summary.php as the front page of your service to achieve the following settings:

This can be implemented via mod_rewrite if you are familiar with it, but there is an easy alternative if you set up an additional virtual host in your Apache server for http://mainsite.com and do a RedirectPermanent directive to http://www.mainsite.com/summary.php

RedicrectPermanent / http://www.mainsite.com/summary.php

This is an example of virtual.conf or httpd.conf:

<VirtualHost *:80>
ServerName www.mainsite.com
ServerAlias *.mainsite.com
<Directory "/home/blog">
DirectoryIndex summary.php index.php
</Directory>
DocumentRoot /home/blog
ErrorLog /var/log/httpd/blabla
CustomLog /var/log/httpd/blabla
</VirtualHost>
<VirtualHost *:80>
ServerName mainsite.com
RedirectPermanent / http://www.mainsite.com/summary.php
</VirtualHost> 

Additional resources

How to configure Apache when using wildcard domains: