How do I redirect www.domain.com to domain.com

5470 views
Skip to first unread message

peter

unread,
Apr 30, 2008, 11:43:25 PM4/30/08
to Google App Engine
Hi,

I have my site setup and working on http://digglicious.com and
http://www.digglicious.com, but I would like the www.digglicious.com
address to redirect to digglicious.com, and for it to include any
subsequent url. ie www.digglicious.com/about will redirect to
digglicious.com/about. I know how to do this with apache, but don't
know the best way to do this with python/GAE.

Cheers
Peter

manatlan

unread,
May 1, 2008, 3:22:26 AM5/1/08
to Google App Engine
in your google app domain administration
just add your url "digglicious.com" to your gae-id
(you should have 2 urls, one with www. one without)

it works for me

On May 1, 5:43 am, peter <peter.marri...@gmail.com> wrote:
> Hi,
>
> I have my site setup and working onhttp://digglicious.comandhttp://www.digglicious.com, but I would like thewww.digglicious.com
> address to redirect to digglicious.com, and for it to include any
> subsequent url.   iewww.digglicious.com/aboutwill redirect to

peter

unread,
May 1, 2008, 3:55:06 AM5/1/08
to Google App Engine
Hi Manatlan,

Thanks for the response, but I already have it working like you
explain, what I want is to automatically redirect them to the site
without the www. I assume their is some python filter or WSGI filter
I could use to do this, but being new to both these I don't know the
best way to do this.

Cheers
Peter

Roberto Saccon

unread,
May 1, 2008, 4:02:47 AM5/1/08
to Google App Engine
you have to set the A records in your Name server configuration for
that domain, to point to Google servers IPs, that is well described in
the google help pages.

peter

unread,
May 1, 2008, 4:21:54 AM5/1/08
to Google App Engine
I am obviously not explaining this well, so I'll try again.

My current situation:
1) digglicious.com works fine and my app displays and works
2) www.digglicious.com works fine and my app displays and works.

What I want:
1) www.digglicious.com to REDIRECT to digglicious.com.
2) www.digglicious.com/anyoldurl to REDIRECT to digglicious.com/
anyoldurl

I don't like having the www, but I do want to redirect anyone who
accidentally uses it, and for users who have bookmarked pages from
when this site was hosted elsewhere.

I have done this in the past using PHP, and apache mod rewrite, what I
don't know how to do is to do this in python/WSGI.

Cheers
Peter

Matteo Crippa

unread,
May 1, 2008, 6:30:16 AM5/1/08
to Google App Engine
the quickest way could be the one you point only your www-less domain
to GAE and all the other to your existing hosting and on www root
place a .htaccess or index.php with a 301 redirect to digglicious.com

on the other hand you can try do something like this

from os import environ

and then on in your app

if "www.digglicious.com" in environ['HTTP_HOST']:
self.redirect("http://digglicous.com")

this is only for base case on root, you will have to work also on all
other urls redict, you can do this using environ['REQUEST_URI']

Btw never tested it, and i don't know which kinda redirect (i don't
think it's a 301) is used in this way...

Hope this helps


On 1 Mag, 10:21, peter <peter.marri...@gmail.com> wrote:
> I am obviously not explaining this well, so I'll try again.
>
> My current situation:
> 1) digglicious.com works fine and my app displays and works
> 2)www.digglicious.comworks fine and my app displays and works.
>
> What I want:
> 1)www.digglicious.comto REDIRECT to digglicious.com.
> 2)www.digglicious.com/anyoldurlto REDIRECT to digglicious.com/

pedrolima

unread,
May 1, 2008, 1:09:48 PM5/1/08
to Google App Engine
If you are using django you can use this middleware to remove the www
as
you want.

http://www.djangosnippets.org/snippets/653/

Regards,
Pedro Lima

On May 1, 9:21 am, peter <peter.marri...@gmail.com> wrote:
> I am obviously not explaining this well, so I'll try again.
>
> My current situation:
> 1) digglicious.com works fine and my app displays and works
> 2)www.digglicious.comworks fine and my app displays and works.
>
> What I want:
> 1)www.digglicious.comto REDIRECT to digglicious.com.
> 2)www.digglicious.com/anyoldurlto REDIRECT to digglicious.com/

Chris L

unread,
May 1, 2008, 1:13:07 PM5/1/08
to Google App Engine
The default is a temporary redirect. There is a parameter you set if
you want it to be permanent - which you probably want to do.

It might be OK to redirect all 'www' requests to the same location. It
handles just fine the case where people typed it by mistake. Is there
any other reason to have 'www' work at all?

Matteo Crippa

unread,
May 2, 2008, 6:15:13 AM5/2/08
to Google App Engine
With reference to the manual you have to do this to have a permanent
redirect:

redirect(uri, permanent=False)
A shortcut method for handlers to use to return a redirect
response. Sets the HTTP error code and Location: header to redirect to
uri, and clears the response output stream. If permanent is True, it
uses the HTTP status code 301 for a permanent redirect. Otherwise, it
uses the HTTP status code 302 for a temporary redirect.

so redirect(url,True)

the only problem i'm dealing with at this moment is connected to the
fact that environ var doesn't have any reference to DOCUMENT_URI or
SCRIPT_URI and going on...

you can try with HTTP_HOST or SERVER_NAME, and then looking at
PATH_INFO in order to redirect the request to the right place in the
www-less domain.

Martin

unread,
Jun 17, 2008, 5:06:39 PM6/17/08
to Google App Engine
You want to redirect foo.com (a few A records) to www.foo.com (CNAME),
not vice versa.

This way you can utilize the geolocality feature.

You will be stuck with round robin rotation using A records.


On May 2, 1:15 pm, Matteo Crippa <matteo.cri...@gmail.com> wrote:
> With reference to the manual you have to do this to have a permanentredirect:
>
> redirect(uri, permanent=False)
>     A shortcut method for handlers to use to return aredirect
> response. Sets the HTTP error code and Location: header toredirectto
> uri, and clears the response output stream. If permanent is True, it
> uses the HTTP status code 301 for a permanentredirect. Otherwise, it
> uses the HTTP status code 302 for a temporaryredirect.
>
> soredirect(url,True)
>
> the only problem i'm dealing with at this moment is connected to the
> fact that environ var doesn't have any reference to DOCUMENT_URI or
> SCRIPT_URI and going on...
>
> you can try with HTTP_HOST or SERVER_NAME, and then looking at
> PATH_INFO in order toredirectthe request to the right place in the
> www-less domain.
>
> On 1 Mag, 19:13, Chris L <clun...@gmail.com> wrote:
>
> > The default is a temporaryredirect. There is a parameter you set if
> > you want it to be permanent - which you probably want to do.
>
> > It might be OK toredirectall 'www' requests to the same location. It
> > handles just fine the case where people typed it by mistake. Is there
> > any other reason to have 'www' work at all?
>
> > On May 1, 6:30 am, Matteo Crippa <matteo.cri...@gmail.com> wrote:
>
> > > the quickest way could be the one you point only your www-less domain
> > > to GAE and all the other to your existing hosting and on www root
> > > place a .htaccess or index.php with a 301redirectto digglicious.com
>
> > > on the other hand you can try do something like this
>
> > > from os import environ
>
> > > and then on in your app
>
> > > if "www.digglicious.com" in environ['HTTP_HOST']:
> > >  self.redirect("http://digglicous.com")
>
> > > this is only for base case on root, you will have to work also on all
> > > other urls redict, you can do this using environ['REQUEST_URI']
>
> > > Btw never tested it, and i don't know which kindaredirect(i don't

Jonathan Feinberg

unread,
Jun 17, 2008, 8:20:51 PM6/17/08
to Google App Engine
> I have my site setup and working onhttp://digglicious.comandhttp://www.digglicious.com, but I would like thewww.digglicious.com
> address to redirect to digglicious.com, and for it to include any
> subsequent url.   iewww.digglicious.com/aboutwill redirect to
> digglicious.com/about.  I know how to do this with apache, but don't
> know the best way to do this with python/GAE.

One way to do it:

class WordleRequestHandler(webapp.RequestHandler):
def wrong_url(self):
if self.request.host == 'www.wordle.net':
self.redirect('http://wordle.net%s'%self.request.path_qs,
permanent=True)
return True
return False

class Whatever(WordleRequestHandler):
def get(self):
if self.wrong_url():
return
# do something


niklasr

unread,
Jun 18, 2008, 5:19:02 AM6/18/08
to Google App Engine, Neil Cleland, Kaj Huggare, Alex Hultmark, Km, Otto Dandenell, Peder Linder
On Jun 17, 11:06 pm, Martin <mtsac...@gmail.com> wrote:
> You want to redirect foo.com (a few A records) towww.foo.com(CNAME),
> not vice versa.
Exactly my problem. There are A-records supplied from Google but these
don't work for us ( 216.239.32.21 , 216.239.34.21 , 216.239.36.21 ,
216.239.38.21 ) .
It only works for us with domains bought and hosted from google and
godaddy. My DNS provider says I should ask Google how to redirect
http://domain.tld to http://www.domain.tld. I have www.domain.tld set
upp with the app engine but the domain.tld still points to my LAMP
that I migrate from. These are the instruction from google, which
don't work since you can't set a CNAME directly on a domain. I believe
a CNAME can't be blank.

1.

Sign in to your domain hosting service.
2.

Navigate to your DNS Management page. The location and name of
this page will vary by host, but can generally be found in Domain
Management or Advanced Settings.
3.

Find the CNAME settings and enter the following as the CNAME
value or alias:

4.

Set the CNAME destination to the following address:

ghs.google.com

Martin

unread,
Jun 18, 2008, 6:24:00 AM6/18/08
to Google App Engine
Niklas,

these IPs work for me.

You just have to click on "Yes, I've done these steps" even though you
add 4 A records instead of 1 CNAME.

I'll see if I can report that to Google so they don't confuse people.

niklasr

unread,
Jun 18, 2008, 6:59:59 AM6/18/08
to Google App Engine
Yes the numbers work so that access works but not redirect. Shall we
even add an access URL for the domain.tld in addition to the access
URL www if all we want is a redirect from foo.com to www.foo.com? I
think not. Maybe I just have to wait for the DNS to synchronize. If we
don't set up the domain.tld as access URL, using these IP numbers
should generate a redirect from foo.com to www.foo.com with just one
access URL for the app (www).
Thank you

niklasr

unread,
Jun 19, 2008, 2:35:03 AM6/19/08
to Google App Engine
We want something like
RewriteEngine on
RewriteCond %{HTTP_HOST} ^foo.com
RewriteRule ^(.*)$ http://www.foo.com/$1 [R=permanent,L]
so we won't have to redeploy our app just for this. Or as a DNS
setting, if possible.
Is it possible?
Thank you
Niklas

On 18 Juni, 12:59, niklasr <nikla...@gmail.com> wrote:
> Yes the numbers work so that access works but not redirect. Shall we
> even add an access URL for the domain.tld in addition to the access
> URL www if all we want is a redirect from foo.com towww.foo.com?I
> think not. Maybe I just have to wait for the DNS to synchronize. If we
> don't set up the domain.tld as access URL, using these IP numbers
> should generate a redirect from foo.com towww.foo.comwith just one

Mike Hearn

unread,
Jun 19, 2008, 5:12:24 PM6/19/08
to Google App Engine
It'd be a really bad idea to do that, please don't.

www.foo.net when foo.net is an AppEngine domain should be a CNAME to a
Google controlled domain name. This is not a normal domain name, it's
load balanced and will resolve to different IPs depending on who is
asking. In contrast, the IPs for a top-level domain like "http://
foo.net" is fixed. For this reason it's always better to have users be
hitting IPs derived from the load balanced name.

Notice that browsing to http://google.com/ will immediately redirect
you to the www.google.com version. This is not for aesthetic reasons.
It results in a faster and more reliable browsing experience.

Roberto Saccon

unread,
Jun 19, 2008, 6:53:04 PM6/19/08
to Google App Engine
With this kind of cloud environments, for best performance and
reliable browser experience it makes most sense to use www.foo.net as
default (and redirect foo.net to www.foo.net) as pointed out by
several posters. I am wondering why Google is not explicitly
recommending this at the article where they explain how to set the A-
records for foo.net.

And I am wondering why people still want to redirect www.foo.net to
foo.net ? Are there cases where for some non technical reasons URL
aesthetics are more important ? Maybe .. Or is it just the customer
who wants it, pays for it and doesn't want to get educated about doing
things better ?

Roberto

On Jun 19, 6:12 pm, Mike Hearn <mh.in.engl...@gmail.com> wrote:
> It'd be a really bad idea to do that, please don't.
>
> www.foo.netwhen foo.net is an AppEngine domain should be a CNAME to a
> Google controlled domain name. This is not a normal domain name, it's
> load balanced and will resolve to different IPs depending on who is
> asking. In contrast, the IPs for a top-level domain like "http://
> foo.net" is fixed. For this reason it's always better to have users be
> hitting IPs derived from the load balanced name.
>
> Notice that browsing tohttp://google.com/will immediately redirect
> you to thewww.google.comversion. This is not for aesthetic reasons.

Chris L

unread,
Jun 19, 2008, 7:09:14 PM6/19/08
to Google App Engine
Yahoo Developer Network has pointed out that using 'www.example.com'
instead of 'example.com' allows you to set cookies on 'www' and the
cookies won't be sent to other subdomains you might have. Good idea
for performance.

http://developer.yahoo.com/performance/rules.html#cookie_free

On Jun 19, 6:53 pm, Roberto Saccon <rsac...@gmail.com> wrote:
> With this kind of cloud environments, for best performance  and
> reliable browser experience it makes most sense to usewww.foo.netas
> default (andredirectfoo.net towww.foo.net) as pointed out by

niklasr

unread,
Jun 19, 2008, 9:10:42 PM6/19/08
to Google App Engine
If the domain was bought from Go Daddy you can activate domain
forwarding to www and this will take care of it. And if the domain was
bought from google forwarding will be deafult. So I have two domains
set up forwarding correctly to www. But not all DNS providers seem to
be supply this feature. So other domains I want to connect are missing
this forwarding feature as it could not get provided as a DNS setting
and there is no known way to configure our web server to redirect
except reprogram the dispatcher which isn't an elegant solution.

Niklas

oli

unread,
Jun 20, 2008, 4:02:48 AM6/20/08
to Google App Engine
Hi Chris,

thanks for the hint, I guess this will solve some HTTP accelerator
problems with a subdomain I had. I don't like the www prefix, but I
will use example.com and example.net.

On Jun 20, 1:09 am, Chris L <clun...@gmail.com> wrote:

niklasr

unread,
Jun 21, 2008, 11:49:53 PM6/21/08
to Google App Engine
I'll use the following to achieve the redirect from the domain to www.
Can this be configured in app.yaml?

host_name = os.environ['HTTP_HOST']
if host_name == 'foo.com':
application = webapp.WSGIApplication(
[('(.*)', RedirectHandler),],
False)

wsgiref.handlers.CGIHandler().run(application)


class RedirectHandler(webapp.RequestHandler):
def get(self,path):
self.redirect("http://www.foo.com%s" % (path), True)

niklasr

unread,
Jul 10, 2008, 2:57:06 AM7/10/08
to Google App Engine, Alex Hultmark, Km
This redirect code seems to work for me but is not very convenient. It
there a better pure GAE solution to redirect http://domain.tld to
http://www.domain.tld as well as adding sub-domains e g http://static.domain.tld
for my http://domain.tld/_/ ? I heard rewriting http://static.domain.tld
to http://domain.tld/_/ will improve response time as downloads may
occur more in parallel.
Thank you
Niklas

Richie

unread,
Jul 23, 2008, 5:19:08 PM7/23/08
to Google App Engine
I hope this post will answer most common questions:

to redirect mydomain.tld and www.mydomain.tld to myapp.appspot.com you
have to own the domain and have the possibility to edit your dns
records.

Enable Google Apps for your GAE-app. Set mydomain.tld as the domain.
(GAE-admin console)

Add URLs http://mydomain.tld and http://www.mydomain.tld for Google
App Engine. (Google Apps admin console)

Go to your DomainServer.

Add an A-record vor mydomain.tld like discripted here.
http://www.google.com/support/a/bin/answer.py?answer=91080

Add a CNAME-record for www.mydomain.tld to ghs.google.com like written
here. http://www.google.com/support/a/bin/answer.py?answer=47283

Add a CNAME-record for something like
googlefffggghhh12345.mydomain.tld to google.com (see last link)

Let Google Apps check your settings.

now you can these urls show the same GAE-app:

http://myapp.appspot.com
http://mydomain.tld
http://www.mydomain.tld


have fun,

Richie
http://eaglefeed.me

Kijan maharjan

unread,
Sep 22, 2016, 9:11:00 AM9/22/16
to Google App Engine, rockete...@gmail.com
@richie How can we use only one domain without www. or may be to redirect www to non www.

Nick (Cloud Platform Support)

unread,
Sep 23, 2016, 1:11:06 PM9/23/16
to Google App Engine, rockete...@gmail.com
Hey Kijan,

What you're describing is called a "naked domain", and this is described in the documentation on Custom Domains.

Cheers,

Nick
Cloud Platform Community Support
Reply all
Reply to author
Forward
0 new messages