title: How can I alias or rewrite a set of resource routes to another namespace in Rails 4?
body: <p>I have a bunch of resources that I want to make available at both <code>/api/[PATH]</code> and <code>/api/v1/[PATH]</code>. In other words, both <code>/api/tasks/12</code> and <code>/api/v1/tasks/12</code> should be routed to <code>Api::V1::TasksController#show</code>. However, for reasons of backward-compatibility I <em>don't</em> want to use external redirects - all the routing should happen internally.</p>
  
  <p>This is the best I've found so far, but it requires replicating the <code>resource</code> declarations:</p>
  
  <pre><code>  namespace :api, defaults: {format: :json} do
      namespace :v1, as: 'v1' do
        resource :profile, only: [:show]
        resources :notifications, only: [:create]
        resources :tasks, only: [:index, :create, :show, :update]
      end
  
      scope module: 'v1' do
        resource :profile, only: [:show]
        resources :notifications, only: [:create]
        resources :tasks, only: [:index, :create, :show, :update]
      end
    end
  </code></pre>
  
  <p>Yes, I could put them in a Proc if I really wanted to avoid duplication, but that just seems ridiculous.
  I tried something like <code>match '*path', path: '/v1', via: :all</code> (inside the first <code>namespace</code>) but that didn't seem to work.</p>
  
  <p>Surely there's a better way of doing this?</p>