Fixes #2477 - Implemented optional subdomains by matching right-to-left

@DASPRID
@fatmuemoo
@ralphschindler

This fixes #2477 by matching the hostname from right-to-left. Once an optional segment is found, the rest must be optional. Existing tests have not been changed and all pass so this should have no BC break.