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.