GAE应用程序app.yaml VS .htaccess [英] GAE Application app.yaml VS .htaccess

查看:97
本文介绍了GAE应用程序app.yaml VS .htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写应用程序Yaml看起来像下面的htacess

How to Write a app yaml looks like htacess below

    RewriteEngine on
    # To append a query string part in the substitution string
    RewriteRule ^([0-9a-z_/\-]+)/$ index.php\?p=$1 [QSA]
    RewriteRule ^([0-9a-z_/\-]+)$ index.php\?p=$1 [QSA]

我在应用yaml for GAE应用程序上这样做失败了

im doing so at app yaml for GAE Application was fail

推荐答案

正如Dan所提到的,您将无法在所有这些内容中进行处理yaml,并且需要自己处理逻辑,我们在我们的一个项目中做了类似的事情,并在解决方案下方进行了概述。

as Dan mentioned, you will not be able to handle this all in the yaml, and will need to to handle the logic yourself, we do a simular thing in one of our project and will outline below our solution.

我们的方案正在处理旧网站文章的URL结构,并尝试将其重定向到新的URL结构。

Our scenario is handling the old website article's URL structure, and trying to redirect them to the new URL structure.

在我们的Yaml中,我们注册了我们希望匹配的模式并将其定向到

In our yaml we register the pattern that we are looking to match on and direct it to a file where we will do the handling :

- url: (/.*/[0-9]{4}/[0-9]{2}/[0-9]{2}/.*)  (Pattern to match on)
  script: publication.custom.redirector.app (Path to your .py that will have your handling in)

在我们的.py文件中,我们将捕获该模式并将其路由到我们的DefaultHandler,然后它可以执行您需要的任何逻辑并重定向出去:
(在我们的项目中,此路径进入/ publication / custom / redirector。 py)

In our .py file we will catch that pattern and route it to our DefaultHandler that can then do any logic you need and redirect out: ( in our project this goes to /publication/custom/redirector.py )

import request
import settings
import re

class DefaultHandler(request.handler):

    def get(self, pre, year, month, day, post):

        post = re.sub('(.*[^0-9])[\d]{1}$', r'\1', post)
        post = re.sub('[^0-9a-zA-Z-_\/]+', '', post)
        path = post.split("/")[-1]
        slug = "{0}-{1}-{2}-{3}".format(year, month, day, path)

        article = self.context.call('pub/articles/get', slug=slug.lower())
        if article:
            self.redirect(article['pub_url'], permanent=True)
        else:
            self.render("pages/page-not-found/page-not-found.html")


app = request.app([
    ('/(.*)/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)', DefaultHandler)
], settings.gaext.config)

希望这会有所帮助

这篇关于GAE应用程序app.yaml VS .htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆