Arc Forumnew | comments | leaders | submitlogin
www to non-www redirect in svr.arc
1 point by markkat 5003 days ago | 9 comments
Has anyone done this?

I've implemented the svr-misc1 patch: http://awwx.ws/srv-misc1 but am struggling.

Any advice would be appreciated.



1 point by aw 5002 days ago | link

With the svr-misc1 patch the "Host" header will be available in the request. For example, if I'm browsing to www.example.com:8080/foo/bar, then

  (alref req!headers "Host")
will be "www.example.com:8080".

I can then extend respond to take action for a particular host

  (extend respond (req) (begins (alref req!headers "Host") "www.")
    ...)
such as by issuing a redirect, something like:

  (extend respond (req) (begins (alref req!headers "Host") "www.")
    (prn "HTTP/1.0 302 Moved")
    (prn "Location: example.com/foo/bar")
    (prn))
sorry I haven't tested this; you'll want to look at what you actually get with a tool like curl to make sure that it's right.

-----

1 point by aw 5000 days ago | link

correction: the "Location" header should include the full URL including the http: or https:. Also you may want a 301 "moved permanently"...:

  HTTP/1.0 301 Moved Permanently
  Location: http://www.example.org/foo/bar

-----

1 point by markkat 5002 days ago | link

Thanks aw. I'll do my best to take it from there. It's appreciated. I've so little experience with this.

-----

2 points by aw 5002 days ago | link

Do post again as soon as you run into any problems or get stuck anywhere. (It will not only help you, but also the people who come after you who need the same thing you do).

-----

1 point by markkat 5001 days ago | link

Will do. It might take a a few days to get to this, but I'll post my problems, and hopefully, progress. :)

-----

1 point by akkartik 5002 days ago | link

I don't follow what you mean by 'www to non-www redirect'. Can you elaborate?

-----

1 point by rocketnia 5002 days ago | link

I believe it means responding to a request to "www.example.com" by sending a 301 redirect to the corresponding URL at "example.com".

Recently, I've been discovering that the www is a good idea in certain ways. Cookies are sent to servers based on the domain name, so having that www there is a good way to make sure that you'll be able to have a subdomain which isn't sent those cookies (say, because it's served in a way you don't fully trust, or because it's a static file subdomain which shouldn't have to wait for the browser to send it superfluous cookies). I'm kinda not sure how it all works right now, but it's got me paranoid. But I digress; whether the redirection should be done is not the question here. ^_^

-----

2 points by akkartik 5002 days ago | link

Ah, I see. I tend to put that kind of stuff in the reverse proxy (I would never hook arc up directly to port 80). Here's the relevant part of readwarp's nginx config:

  server {
    listen   80 default;
    server_name  readwarp.com alias www.readwarp.com;
    ..
  }
Apache has similar syntax, but I am happy to report I have forgotten what it is.

-----

1 point by markkat 5002 days ago | link

Yes, rocketnia is right. That's what I'm getting at. I haven't used a reverse proxy yet. But I am at least using the setuid line in svr.arc now. ;)

-----