The Internet
The Internet

Reputation: 8123

Match on site root, with snap webframework

I'm building a site with Snap.

In my routes, how do I match on the site's root directory?

i.e.

routes = [(ByteString, Handler App App ())]
routes = [("/", redirect "www.google.com")]

The above code doesn't redirect when called at(localhost:8000/).

Upvotes: 0

Views: 158

Answers (2)

phatmann
phatmann

Reputation: 18503

If you have a template called index.tpl, then the "/" handler will never get called. I found this out through trial and error.

Upvotes: 2

Rodrigo Taboada
Rodrigo Taboada

Reputation: 2727

You need to add "http://" to the URI. This works in my machine:

routes = [("/", redirect "http://www.google.com")]

You can also use ifTop:

site :: Snap ()
site = ifTop (redirect "http://www.google.com) <|>
       route routes 

Where routes contains the remaining routes of your site.

Upvotes: 1

Related Questions