如何将请求从 Rails 重定向到 PHP 子域?

发布于 2024-08-19 01:54:25 字数 450 浏览 2 评论 0原文

我有一个网站,例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瑶笙 2024-08-26 01:54:25
ActionController::Routing::Routes.draw do |map|

  map.connect '20/:name', :controller => :twenty, :action => :show
  map.resources :twenty, :as => '20', :only => [:index, :show] 

  map.connect ':url', :controller => :archive, :action => :show,
                     :requirements => { :url => /(([0-1]){1}([0-9]){1})(.*)/ }

  map.root :controller => :pages, :action => :cover  

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

对于任何来自domain/00 到domain/19 的请求,我在控制器中重定向

redirect_to "http://archive.example.com/#{params[:url]}", :status => 301
ActionController::Routing::Routes.draw do |map|

  map.connect '20/:name', :controller => :twenty, :action => :show
  map.resources :twenty, :as => '20', :only => [:index, :show] 

  map.connect ':url', :controller => :archive, :action => :show,
                     :requirements => { :url => /(([0-1]){1}([0-9]){1})(.*)/ }

  map.root :controller => :pages, :action => :cover  

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

For any request coming to domain/00 to domain/19 I redirect in the controller

redirect_to "http://archive.example.com/#{params[:url]}", :status => 301
不爱素颜 2024-08-26 01:54:25

此方法是最简单的,并且还有发送 301 标头的额外好处。这对于提高你的 SEO 评级真的很有好处!

<?php 
$uri = $_SERVER['REQUEST_URI']; // Gets the user's current URI
$redirect = array("/00/author-name/index.php", "/19/author-name.php"); //Define your 301 redirect uri

// Here's the meet and greet of your problem:
if (in_array($uri, $redirect)) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: archive.example.com");
}
?>

确保将此代码放在脚本或引导程序的开头

使用此方法,您不仅可以重定向您的受众,同时还可以通知谷歌(或任何搜索引擎):的改变。这将使谷歌立即更新其索引。

This method is the easiest and with the added bonus of sending a 301 header. This is really good to improve your SEO rating!!!

<?php 
$uri = $_SERVER['REQUEST_URI']; // Gets the user's current URI
$redirect = array("/00/author-name/index.php", "/19/author-name.php"); //Define your 301 redirect uri

// Here's the meet and greet of your problem:
if (in_array($uri, $redirect)) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: archive.example.com");
}
?>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文