【发布时间】: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为什么会这样?对我来说毫无意义。这是管理网站的基本部分