如何在Google App Engine上强制“WWW”? [英] How to Force 'WWW' on Google App Engine?

查看:133
本文介绍了如何在Google App Engine上强制“WWW”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Google App Engine上强制WWW?对于我的PHP脚本,我使用:

$ $ p $ <?php
if(substr($ _ SERVER ['' SERVER_NAME'],0,4)=! 'WWW'){
标题( 位置:HTTPS:// WWW {$ _SERVER [ 'SERVER_NAME']} {$ _SERVER [ 'REQUEST_URI']} );
}
?>

但显然,这对于机器人等静态文件不起作用。 txt 和 sitemap.xml



例如 https://example.com/robots.txt 不会重定向到 https://www.example.com/robots.txt
例如 https://example.com/sitemap.xml 不会重定向到 https://www.example.com/sitemap.xml

请指教。

解决方案

我用我的DNS提供商的服务确实为裸域的WWW子域名重定向。



在WWW子域名,然后映射到App Engine的实例。

您可以访问gflip.net作为示例。



这种方法的缺点是裸体domain永远不会被使用,但这对我来说至少不是问题 - 它甚至可以用于SSL连接。



希望这有助于您。


How to force 'WWW' on Google App Engine? For my PHP scripts, I'm using:

<?php
if (substr($_SERVER['SERVER_NAME'], 0, 4) != 'www.') {
    header("Location: https://www.{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}");
}
?>

But obviously, this wouldn't work for static files such as robots.txt and sitemap.xml.

e.g. https://example.com/robots.txt would not redirect to https://www.example.com/robots.txt e.g. https://example.com/sitemap.xml would not redirect to https://www.example.com/sitemap.xml

At first, I thought I could resolve the issue by only pointing the subdomain (www.example.com) to Google App Engine, but then I realized the naked domain (example.com) wouldn't be reachable.

Please advise.

解决方案

I did a redirect for the naked domain to the WWW subdomain using my DNS provider's service.

The WWW subdomain then maps to the App Engine instance.

You can visit gflip.net as an example.

The drawback of this approach is that the naked domain is never used, but this is not been a problem for me at least - it even works for SSL connections.

Hope this helps.

这篇关于如何在Google App Engine上强制“WWW”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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