fixing permanent redirect with middleware