views:

83

answers:

2

I'm working on a site, colorurl.com, and I need users to be able to type in colorurl.com/00ff00 (or some variation of that), and see the correct page. However, with the naked domain issue, users who type in colorurl.com/somepath will instead be redirected to www.colorurl.com/.

Is there a way to detect this in python, and then redirect the user to where they meant to go (With the www. added?)

EDIT:

Clarification: In my webhost's configuration I have colorurl.com forward to www.colorurl.com. They do not support keeping the path (1and1). I have to detect the previous path and redirect users to it.

  1. User goes to colorurl.com/path
  2. User is redirected to www.colorurl.com
  3. App needs to detect what the path was.
  4. App sends user to www.colorurl.com/path
A: 

You need to use a third-party site to do the redirection to www.*; many registrars offer this service. Godaddy's service (which is even free with domain registration) forwards foo.com/bar to www.foo.com/bar; I can't speak to the capabilities of the others but it seems to me that any one that doesn't behave this way is broken.

Wooble
My webhost, 1and1, does not support this.
Josh Patton
Is colorurl.com a python website running on 1and1 and www.colorurl.com a website running on App Engine? If so, all you need to do on the colorurl.com one is serve a redirect to the exact same URL with 'www' prepended in the correct place. You don't say what framework you're using on this other site, so it's hard to be specific as to the syntax.
Wooble
There is no other site. Google App Engine does not allow naked domains. The "other site" is simply a dumb html server (because of the accepted answer, it was previously just mapped to redirect in the dns settings, but the path data would be lost).
Josh Patton
+3  A: 

What I'd do in this scenario is set up a small site at your naked domain which consists of just a .htaccess file which redirects path and all to www.*:

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^colorurl.com [NC] 
RewriteRule ^(.*)$ http://www.colorurl.com/$1 [L,R=301]
Simon Scarfe
Wow... perfect. I was thinking about mod_rewrite, wishing it was usable on App Engine. I didn't think about this kind of solution.
Josh Patton