简体   繁体   English

如何在没有htaccess文件的情况下使https://www.example.com重定向到https://example.com

[英]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.comhttp://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.

相关问题 Rails-如何从http://example.com重定向到https://www.example.com - Rails - How to Redirect from http://example.com to https://www.example.com 如何在Rails 2.3.3中从example.com/products重定向到www.example.com/products - How to redirect to www.example.com/products from example.com/products in Rails 2.3.3 Rails-Puma-Nginx:如何将所有重定向到https://www.example.com? - Rails - Puma - Nginx : How to redirect all to https://www.example.com? example.herokuapp.com重定向到https://example.com - example.herokuapp.com redirection to https://example.com Rails cookie会话共享和“www.example.com”或“example.com”问题 - Rails cookie session sharing and “www.example.com” or “example.com” problem 用Rails应用强制域的最佳方法是什么? 例如:example.com,而不是www.example.com - what's the best way to force a domain with a rails app? ex: example.com instead of www.example.com [HTTP]如何将“ www.example.com”更改为“ localhost:3000” - [HTTP]how to change “www.example.com” to “localhost:3000” Rails:如何显示与www.example.com的链接,但不显示带<a>标签的</a>链接 - Rails: How to show link with www.example.com but not show with <a> tag 如何获得网址为www.example.com/1/product/date/price的网址? - How can I get my URL's to look like www.example.com/1/product/date/price? Rails SSL 问题:(https://example.com) 与 request.base_url (http://example.com) 不匹配 - Rails SSL issue: (https://example.com) didn't match request.base_url (http://example.com)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM