问题
Need to redirect all 404 links to index.html inside www folder
This is my app.yaml
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
It's a static angular 2 app , and i need to direct all page not found 404 errors to index.html. There is (www) folder and inside that all file including index.html there.
回答1:
So adding this as the last rule, will cause it to serve index.html if all other rules fail
- url: /.*
static_files: www/index.html
upload: www/(.*)
But I think what you want is for it to actually perform a redirect; otherwise, your base url will still be some bogus url. You need to setup a basic request handler in server code to do this right (and in your case your server runtime is python27).
So add this rule to app.yaml
- url: /.*
script: main.app
And then add a file called main.py with something like this in it:
import webapp2
app = webapp2.WSGIApplication()
class RedirectToHome(webapp2.RequestHandler):
def get(self, path):
self.redirect('/www/index.html')
routes = [
RedirectRoute('/<path:.*>', RedirectToHome),
]
for r in routes:
app.router.add(r)
来源:https://stackoverflow.com/questions/52856895/how-to-configure-google-app-engine-yaml-file-to-handle-404-error