如何将请求从 Rails 重定向到 PHP 子域?
我有一个网站,例如 example.com,它是 PHP 的。我正在将其转换为 Rails,但有三年的期刊(例如杂志期刊)我不想更新。值得庆幸的是,我似乎选择了一种有利的网址格式,即。所有问题都以两位数字开头,然后是文件名(大多数情况下)
example.com/00/author-name/index.php
example.com/19/author-name.php
我想通过 301 将这些 php 文件的所有请求重定向到
archive.example.com
并使顶级 example.com 成为 Rails 站点,提供最新问题。 ~/20/author-name
子域位于 dreamhost 上,顶级将转到 heroku。 (所以这不是问题的一部分。)谢谢。
I have a site, say, example.com, which is PHP. I am converting it to Rails, but there are three years worth of issues (like magazine issues) that I don't want to update. Thankfully, it seems that I chose an advantageous url format, ie. all issues start with two digits, then the name of the file in most cases
example.com/00/author-name/index.php
example.com/19/author-name.php
I want to redirect via 301 all requests for those php files to
archive.example.com
And make the top level example.com a Rails site, serving up the latest issues.. ~/20/author-name
The subdomain is on dreamhost, and the top level will go to heroku. (So this is not part of the question.) Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看以下答案:
Have a look at the following answers:
对于任何来自domain/00 到domain/19 的请求,我在控制器中重定向
For any request coming to domain/00 to domain/19 I redirect in the controller
此方法是最简单的,并且还有发送 301 标头的额外好处。这对于提高你的 SEO 评级真的很有好处!
确保将此代码放在脚本或引导程序的开头
使用此方法,您不仅可以重定向您的受众,同时还可以通知谷歌(或任何搜索引擎):的改变。这将使谷歌立即更新其索引。
This method is the easiest and with the added bonus of sending a 301 header. This is really good to improve your SEO rating!!!
Make sure to have this code at the very beginning of your script or bootstrap
With this method, you not only redirect your audience and at the same time, you're notifying google (or whatever search engine) of the change. This will make google update it's index in no time.