Topic: Redirecting wildcard routes

I have a simple problem which turned out not to be so simple smile

Consider the following route:

match "*id", :to => "pages#show"

Now this route works:


Only problem is that this route will also work:


What I'd like to do is somehow 302 redirect that puppy so it always points to the wildcard route. I'd like to do this without futzing with my server conf if possible, but so far it seems like the only way.

Any suggestions on how I can accomplish this within Rails?

Re: Redirecting wildcard routes

Are you looking for a 301 or 302 (302 is temporary, means you are going to eventually move it back, 301 is permanent.)  The line below will redirect to /id

match "/pages/:id", to: redirect("/%{id}")

Also, change your old route to match ":id", to: "posts#show"

Last edited by betam4x (2012-10-16 23:37:40)

Re: Redirecting wildcard routes

Thanks betam4x, that's exactly what I was looking for, and you were right it is 301 I was looking for.