Topic: URL Rewrite Problem


I am trying to do this.


instead of doing http://localhost:3000/signups/login/1

How can I rewrite or hack the route file or controller?


Rafeek smile

Re: URL Rewrite Problem

Re: URL Rewrite Problem

Hi danabrit,
              Thanks for the URL Rewrite Tutorial. Can you tell me how can write the URL Write for the below URL in the routes.rb file.

I need to display the URL like this,

instead of


        In my route.rb file i already wrote like this,

        map.home '/home',:controller=>"patient_histories", :action=>"update_histories"

Can you help me on this

Rafeek smile

Re: URL Rewrite Problem

That should be all you need. What does the link_to look like that's generating the extra parameter?

Re: URL Rewrite Problem

Hi danabrit,

            Thanks for the reply, here in my link_to tag i have below format as shown,

<%= link_to "Home" , {:controller => "message_histories", :action => "update_message" ,:id => session[:user_id]} %>

Now i able to get the URL like : http://localhost:3000/home/1
but i don't need the id nor the controller name.

instead i want ,http://localhost:3000/home

can you help me on this.



Re: URL Rewrite Problem

Take the :id parameter out of your link_to.

Re: URL Rewrite Problem

Hi danabrit,

                Thanks. Its works for me. If possible can you tell me, i just want read something from the url at the end has some text like below,

                        http://localhost:3000/home/<some text here>.


    For this,How can read write the route for this ?. I try to read this in my home action like params[:id] it gives me,

No route matches "/rafeekphp" with {:method=>:get}


Rafeek smile

Re: URL Rewrite Problem

You need to read about how routes work. I suggest

Re: URL Rewrite Problem

Hello Daabrik and Rafeek,

I am Kranthi. i am new to Rails. Please forgive me if ask any stupid questions.

I have gone through this article. I am also suffering with the same problem.

my website URL like this:

I don't want to show the User ID and action: edit.

I want to Re-Write (rewrite) the URL or i want to maintain the URL as only.

I am not interested to show the user ID and action (edit)

I want to make the edit action to call the HTTP Verb as POST. I don't..... Want to show any User_id publicly...

Above you are saying that go through the Routing Tech. But, the routing will be helpful to catch the incoming requests coming in different formats only not to rewrite.

I total intension is to Hiding (HIDING) and rewriting (REWRING) the URL and mainly i want to hide the URL Extensions with User ID and actions mainly..

Can u help me on that.... Please.....!!!!! sad

Last edited by kranthipoturaju (2009-12-10 02:51:17)

Re: URL Rewrite Problem

In a comment to an old post of mine about URL rewriting, a visitor named Tim has just asked how to solve a problem he was facing with ASP.NET themes and rewriting. The original post was addressing the main problems by using an overload of the RewritePath method introduced by .NET 2. Yet, a simple problem still existed: whenever URL rewriting is used with a URL like ~/somepath/ the theme gets broken because the path to the CSS files and other themed resources (like images) are wrong. The problem here is the trailing slash, which confuses the theme engine. A URL like ~/somepath works fine of course.

In fact, I recently noticed that I had the same problem with my own URLs on SharpToolbox/JavaToolbox and on a new site I'm working on. What I did to resolve this is to perform a (permanent) redirection to URLs without the ending "/". This is indeed what we wish to express: ~/somepath/ and ~/somepath are the same URLs.

Here is the regular expression I use to identify a problematic URL: ^(.*)/(\?.*)?$
I then redirect to: $1$2
You can notice that this expression also supports URLs with parameters.

If you use UrlRewritingNet.UrlRewrite you can use the following rule:
<add virtualUrl="^(.*)/(\?.*)?$" destinationUrl="$1$2" rewriteUrlParameter="ExcludeFromClientQueryString" redirectMode="Permanent" redirect="Domain" />

If you use my old HTTP module, you should be able to use:
<add targetUrl="^(.*)/(\?.*)?$" destinationUrl="$1$2" permanent="true" />
Posted: Oct 20 2006, 02:48 AM by Fabrice Marguerie | with 13 comment(s)
Filed under: Tips, .NET