如何在Google App Engine上强制“WWW”? [英] How to Force 'WWW' on Google App Engine?
问题描述
如何在Google App Engine上强制WWW?对于我的PHP脚本,我使用:
$ $ p $ <?php
if(substr($ _ SERVER ['' SERVER_NAME'],0,4)=! 'WWW'){
标题( 位置:HTTPS:// WWW {$ _SERVER [ 'SERVER_NAME']} {$ _SERVER [ 'REQUEST_URI']} );
}
?>
但显然,这对于 sitemap.xml
。
例如 https://example.com/robots.txt
不会重定向到 https://www.example.com/robots.txt
例如 https://example.com/sitemap.xml
不会重定向到 https://www.example.com/sitemap.xml $首先,我认为我可以通过将子域(www.example.com)指向Google App Engine来解决问题,但后来我意识到裸域(example.com)不会是可到达的。
请指教。
我用我的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屋!