How to redirect requests from domain.com to www.domain in Wai/Warp app?

徘徊边缘 提交于 2019-12-25 05:09:56

问题


My site is built in Haskell/Servant and Wai/Warp. I need to redirect all requests from my domain.com to www.domain.com with the the 301 or 302 status. I know I can do that with the help of Wai/Warp somehow. How exactly?

startApp :: IO ()
startApp = run 1234 app

回答1:


The package wai-util has a convenience function redirect' to create such a Response, so you should be able to do something like

app :: Application
app req respond = respond =<< redirect' status302 [] uri
  where
    Just uri = parseURI "http://example.com/"


来源:https://stackoverflow.com/questions/36732299/how-to-redirect-requests-from-domain-com-to-www-domain-in-wai-warp-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!