Better handling of directories and permalinks