[英]How to get https://www.example.com to redirect to https://example.com without a htaccess file
I'm using google cloud platform to host my site and namecheap for the domain name. 我正在使用Google Cloud Platform托管我的网站,并为域名便宜。 I want any traffic that hits https://www.example.com to redirect to https://example.com .
我希望所有点击https://www.example.com的流量都重定向到https://example.com 。
I currently have http://www.example.com and http://example.com redirecting to https://example.com from using DNS URL redirects and having secure: always
as a handler in my app.yaml file (for ruby on rails). 我目前可以使用DNS URL重定向将http://www.example.com和http://example.com重定向到https://example.com并具有
secure: always
作为我app.yaml文件中的处理程序(对于红宝石在轨道上)。
I dont know how to have https://www.example.com redirect to https://example.com . 我不知道如何将https://www.example.com重定向到https://example.com 。 I've tried adding a
.htaccess
file but couldn't get it to work so maybe there is a configuration I can have in the app.yaml file or some other way for this to work. 我尝试添加
.htaccess
文件,但无法使其正常工作,因此也许我可以在app.yaml文件中进行配置,或者通过其他方式使其正常工作。
It sounds like you're using App Engine in particular. 听起来您特别在使用App Engine。
I don't think that app.yaml supports matching on the hostname; 我认为app.yaml不支持在主机名上进行匹配; you can either implement the redirect in your application or add a second service to your app which only serves the redirects and use
dispatch.yaml
to route requests to non-canonical domain to the redirect service. 您可以在应用程序中实现重定向,也可以在应用程序中添加仅用于重定向的第二项服务,并使用
dispatch.yaml
将对非规范域的请求路由到重定向服务。
Sample dispatch.yaml
if you decide to use two services: 如果您决定使用两个服务,请样本
dispatch.yaml
:
dispatch:
# Official site is at example.com
- url: "example.com/*"
module: default
# Default module serves simple redirect.
- url: "*/*"
module: redirect
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.