Most of the changes needed per comments.
Upgraded to check for http and https permalinks.