2010-01-20 45 views
2

我有一個網站,比如example.com,它是PHP。我將它轉換爲Rails,但是我不想更新三年的問題(如雜誌問題)。謝天謝地,我似乎選擇了一種有利的網址格式,即。所有問題開始用兩位數字,那麼在大多數情況下如何將Rails的請求重定向到PHP子域?

example.com/00/author-name/index.php
example.com/19/author-name.php

的文件名

我想通過301個所有這些的PHP文件的請求重定向到

archive.example.com

使頂級example.com成爲Rails站點,提供最新的問題..〜/ 20 /作者姓名

子域在dreamhost上,頂層將轉到heroku。 (所以這不是問題的一部分。)謝謝。

回答

1
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 

對於任何要求來域/ 00域/ 19我在控制器

重定向
redirect_to "http://archive.example.com/#{params[:url]}", :status => 301 
0

這種方法是最簡單的,並且還可以發送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"); 
} 
?> 

確保在腳本一開始有這個代碼或引導

使用這種方法,你不僅重定向你的聽衆,並在同一時間,你通知谷歌(或任何搜索引擎)的變化。這將使谷歌立即更新它的索引。

相關問題