Awesome referer hack

I was talking to Roy Leban the other day about how a particular domain registrar of his makes it check-box trivial to redirect from a naked domain (say example.com) to www.example.com, but doesn’t do anything whatsoever to redirect from example.com/someurl to www.example.com/someurl. I was teasing him about needing to get a real domain registrar, but it turns out he has a really slick hack to manage the redirect on the www.example.com side (which happens to be hosted on Google App Engine) since App Engine isn’t cool with naked domains.

What he does is this:

  1. checks the box on his domain registrar to forward from example.com/* to www.example.com/
  2. once the user’s web browser arrive at www.example.com, he checks the HTTP Referer1 header to see if the user came from example.com/something, and, if so,
  3. redirects the user one more time to www.example.com/something based on the Referer (in this case example.com/something).

I’m not sure that solution would have ever occurred to me, but I love it for the hack value.

  1. Merriam-Webster says that should be spelled “Referrer”, but RFC 2068 codified the misspelling “Referer” as the actual header name way too long ago to fix. []

Post a Comment

Your email is never shared. Required fields are marked *

*
*