Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3977718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:57:24+00:00 2026-05-20T04:57:24+00:00

I have a slightly different take on a fairly common problem: SEO-friendly URLs. I

  • 0

I have a slightly different take on a fairly common problem: SEO-friendly URLs. I have a PagesController, so my URLs currently are like (using restful routing):

/pages/some-content-title

This works just fine, but there is a hierarchical structure to the pages so I need the following:

/some-content-title routes to /pages/some-content-title

I can also get this to happen using:

match '*a', :to => 'errors#routing'

in my routes.rb and trapping it in ErrorsController as:

class ErrorsController < ApplicationController
  def routing
    Rails.logger.debug "routing error caught looking up #{params[:a]}"
    if p = Page.find_by_slug(params[:a])
      redirect_to(:controller => 'pages', :action => 'show', :id => p)
      return
    end
    render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
  end
end

My question comes in the desired SEO elimination of the “pages/” part of the URL. What the SEO-dude wants (and here is where an example is key):

/insurance => :controller=>’pages’, :id=>’insurance’ # but the url in the address bar is /insurance

/insurance/car :controller=>’pages’, :category=>’insurance’, :id=>’car’ # but the url in the address bar is /insurance/car

Is there a generic way for him to get his Google love and for me to keep the routes sane?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:57:25+00:00Added an answer on May 20, 2026 at 4:57 am

    This is hard to do since you are redefining the parameters based on their presence (or absence) in the path. You could handle the globbed parameters in the controller, but then you don’t get the URL that you want, and it requires a redirect.

    Rails 3 lets you use a Rack application as an endpoint when creating routes. This (sadly underused) feature has the potential to make routing very flexible. For example:

    class SeoDispatcher
      AD_KEY = "action_dispatch.request.path_parameters"
    
      def self.call(env)
        seopath = env[AD_KEY][:seopath]
        if seopath
          param1, param2 = seopath.split("/") # TODO handle paths with 3+ elements
          if param2.nil?
            env[AD_KEY][:id] = param1
          else
            env[AD_KEY][:category] = param1
            env[AD_KEY][:id] = param2
          end
        end
        PagesController.action(:show).call(env)
        # TODO error handling for invalid paths
      end
    end
    #
    
    MyApp::Application.routes.draw do
      match '*seopath' => SeoDispatcher
    end
    

    will map as follows:

    GET '/insurance'     => PagesController#show, :id => 'insurance'
    GET '/insurance/car' => PagesController#show, :id => 'car', :category => 'insurance
    

    and will retain the URL in the browser that your SEO dude is asking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been done but I have a slightly different twist
Sometimes I have to run multiple queries (one after another) with slightly different arguments
I'm going to re-ask this question in a slightly different way. Say I have
slightly different question about variance this time. I take it from experimentation that C#
This question has been asked before ( link ) but I have slightly different
I have 2 different tables but the columns are named slightly differently. I want
I have three classes that will each return a slightly different result. // interfact
I have slightly altered the architecture of our application, and IWindsorContainer is no longer
I have a slightly modified version of the thread class copied off the Linux
I have a slightly odd situation. One of my customers has an Asp.net (v2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.