Changed replace to only remove blog/ or /blog/ at the start of the link
Changed check for main site to work if the main site is not the default