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 6181925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:06:49+00:00 2026-05-24T01:06:49+00:00

I have a Rails application that uses a static_pages controller to render static pages

  • 0

I have a Rails application that uses a static_pages controller to render static pages within the application and I am looking for the best solution to perform a 301 redirect of specific pages – an example would be /dentist redirected to /dentist-london

I am using Rails 2.3.8.

The static_pages controller looks like this:

class StaticPagesController < ApplicationController

  def display
    if static_page_exists?
      render_static_page
    else
      raise ActiveRecord::RecordNotFound
    end
  end

  protected

  def static_page_exists?
    File.exists? template_path
  end

  def template_path
    File.join('app', 'views', 'static_pages', file_name)
  end

  def render_static_page
    render :template => File.join('static_pages', file_name)
  end

  def file_name
    File.join(params[:path]) + '.html.haml'
  end

end

This controller matches the pages to the name of the static page and renders the content.

The route looks like this:

  map.static_page '*path',  :controller => 'static_pages', :action => 'display'

I can rename the page app/views/static_pages/dentist.html.haml file to app/views/static_pages/dentist-london.html.haml however I am not sure how to perform the 301 redirect on this change.

Can anyone offer any advice?

I think I have included all the relevant code but feel free to ask if anything is missing/doesn’t make sense.

Thanks in advance

  • 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-24T01:06:51+00:00Added an answer on May 24, 2026 at 1:06 am

    If your static mapping set is known and you can infer it via a regex than I would put them in some file of your own devising and then use some Rack middleware to load the file, parse it, and then inspect all incoming requests.

    It sounds like there isnt much of a reason for it to go all the way through your Rails stack, hence a middleware approach is more optimal.

    Maybe your mapping file is something like:

    dentist,dentist-london
    foo,bar
    

    Where if you split on , than the first column is the “source” and the second column is the “destination” to be redirected to. Put that in a Hash for quick lookups and you’re off.

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

Sidebar

Related Questions

I have a project that uses Sinatra for static pages and Rails for the
I have a Rails application that uses Bundler for dependency management. I've got the
I have a rails 3 application that uses Devise and the confirmable module. However,
I am currently working on rails3 application that uses jQuery. I have a javascript
I'm adding a password reset feature to my Rails application that uses Authlogic. I
In a plugin helper, I have: include Rails.application.routes.url_helpers url_for(:only_path => true, :controller => 'people',
I have a search function that performs basic filtering in a Rails 3 application
In a Rails 3.0.6 application that uses Devise I created this link: <%= link_to
I am using Ruby on Rails 3 and I have a monolithic application that
I'm currently looking at hosting solutions for my Ruby on Rails SaaS web application,

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.