more complete code for permalink fallback