Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何配置Google应用程序引擎yaml文件以处理404错误_Angular_Google App Engine_Google Cloud Platform_Angular2 Routing - Fatal编程技术网

Angular 如何配置Google应用程序引擎yaml文件以处理404错误

Angular 如何配置Google应用程序引擎yaml文件以处理404错误,angular,google-app-engine,google-cloud-platform,angular2-routing,Angular,Google App Engine,Google Cloud Platform,Angular2 Routing,需要将所有404链接重定向到www文件夹内的index.html 这是我的应用程序 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/(.*) 这是一个静态angular 2应用程序,我需要将所

需要将所有404链接重定向到www文件夹内的index.html

这是我的应用程序

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/(.*)
这是一个静态angular 2应用程序,我需要将所有未找到的404错误页面定向到index.html。
有一个(www)文件夹,里面有包括index.html在内的所有文件。

因此,如果所有其他规则都失败,将此添加为最后一条规则,将导致它提供
index.html

- url: /.*
  static_files: www/index.html
  upload: www/(.*)
但我认为你想要的是它实际执行重定向;否则,您的基本url仍然是一些伪造的url。您需要在服务器代码中设置一个基本的请求处理程序来正确执行此操作(在您的情况下,您的服务器运行时是
python27

因此,将此规则添加到
app.yaml

- url: /.*
  script: main.app
然后添加一个名为
main.py
的文件,其中包含如下内容:

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)
导入webapp2
app=webapp2.WSGIApplication()
类RedirectToHome(webapp2.RequestHandler):
def get(自我,路径):
self.redirect('/www/index.html')
路线=[
重定向路由(“/”,重定向到主页),
]
对于路线中的r:
应用程序路由器添加(r)

这是否适用于PathLoactionStrategy?