Bilbo Baggins
Bilbo Baggins

Reputation: 3692

404 Not Found: self.request.url

I want to redirect all requests to a Google App Engine server to another server.

eg. www.abc.com/aaa will be redirected to www.xyz.com/aaa

However I get 404 Not Found - The resource could not be found error.

When I try to load any url apart from the home url (www.abc.com)

app.yaml

handlers:
- url: /favicon\.ico   static_files: favicon.ico   upload: favicon\.ico

- url: /.*   script: main.app

libraries:
- name: webapp2   version: "2.5.2"

main.app

import webapp2

class MainHandler(webapp2.RequestHandler):
    def get(self):
        x = self.request.url
        #self.response.write(x)

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

Upvotes: 1

Views: 352

Answers (1)

Sainath Motlakunta
Sainath Motlakunta

Reputation: 945

Change this:

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

to this:

app = webapp2.WSGIApplication([
    ('/.*', MainHandler)
], debug=True)

Add a wildcard so that all requests are sent to MainHandler.

Another suggestion please use

self.redirect(url)

Instead of

self.response.write(url)

Hope this helps! :)

Upvotes: 2

Related Questions