如何在Wai/Warp应用中将请求从domain.com重定向到www.domain? [英] How to redirect requests from domain.com to www.domain in Wai/Warp app?

查看:90
本文介绍了如何在Wai/Warp应用中将请求从domain.com重定向到www.domain?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站建在Haskell/Servant和Wai/Warp中.我需要将状态为301或302的所有请求从我的 domain.com 重定向到 www.domain.com .我知道我可以以某种方式在Wai/Warp的帮助下做到这一点.到底是什么?

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

推荐答案

wai-util 具有便捷功能

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/"

这篇关于如何在Wai/Warp应用中将请求从domain.com重定向到www.domain?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆