【问题标题】:Apply 301 redirect in Google App Engine Standard在 Google App Engine 标准中应用 301 重定向
【发布时间】:2021-08-19 14:00:59
【问题描述】:

我们需要将所有 www 流量路由到非 wwww。所以https://www.mywebsite.com应该301重定向到https://mywebsite.com

在 GAE 中,您不能使用 .htaccess 文件,所以我认为唯一的选择是在 Nginx 配置中执行此操作。

我创建了一个测试项目来测试这个。

这是一个带有以下app.yaml的Hello World应用程序:

runtime: php74

runtime_config:
  nginx_conf_include: nginx-app.conf

nginx-app.conf 文件与app.yaml 处于同一级别,并具有以下内容:

# Redirect www to non-www
if ( $host ~ ^www\.(?<domain>.+) ) {
    rewrite ^/(.*)$ $scheme://$domain/$1;
}

文档指出该文件是: Filename of a partial nginx config which will be included in the server section in the main nginx config file.

使用 www 访问我的项目 URL 会出现不安全的 SSL 错误并且不会重定向。

如何在 Google App Engine Standard 中应用 301 重定向?

【问题讨论】:

  • 我会在您自己的代码中进行重定向,而不是尝试使用 nginx。我认为您不能将 nginx 与 GAE 标准一起使用。
  • 我认为你是对的。我一定一直在看 flex 文档。这很奇怪。除了在 PHP 中做之外,真的没有办法处理 301 重定向吗? GAE为什么会这样?对我来说毫无意义。这是管理网站的基本部分

标签: nginx google-app-engine


【解决方案1】:

就像@gaefan 提到的,我认为应用引擎标准不能提供 nginx 文件。

如果您想为这两个域提供服务,在 App Engine 标准环境中,更简单的方法是创建一个单独的服务(我们称之为redirect)并使用dispatch.yaml 将所有https://www.mywebsite.com 路由到redirect,并在那里处理重定向请求。

【讨论】:

    猜你喜欢
    • 2012-09-22
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 2011-05-12
    • 1970-01-01
    相关资源
    最近更新 更多