This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
CNAME 不是重定向,而只是您的域的规范名称。这意味着它的行为就像它指向的域(在您的例子中是 myapp.com )。您的浏览器获取与 myapp.com 相同的 IP 地址并向其发送请求。
重定向在 HTTP 级别或更高级别执行。例如,您可以在您的应用程序中执行此操作,或者为此创建另一个简单的应用程序。
下面是一个直接在您的应用中进行重定向的简单示例:
或者您可以使用 Rails Metal,它会执行相同的操作,但速度更快:
您还可以使用正则表达式来匹配所有带有
www.
的请求。在主机名前面。CNAME is not a redirect but only a canonical name for your domain. That means that it behaves just like the domain it points to (myapp.com in your case). Your browser gets the same IP address as myapp.com has and sends a request to it.
Redirects are performed at the HTTP level or above. You can do this for example in your app or create another simple app just for that.
Here's a simple example to do the redirect directly in your app:
Or you could use rails metal, which would do the same, but much faster:
You could also use a Regex to match all requests with
www.
in front of the hostname.这里有一个针对node.js的解决方案,
这也会将domain.herokuapp.com重定向到yourdomain.com,防止搜索引擎索引重复内容。
And here's a solution for node.js
This will also redirect domain.herokuapp.com to yourdomain.com, preventing search engines indexing duplicate content.
您还可以在任何 Rack 应用程序中轻松完成此操作,只需安装
rack-canonical-host
gem 并将其放入 Rack 配置文件中即可:You can also do this pretty easily in any Rack app, by installing the
rack-canonical-host
gem and putting this in your Rack config file: