# URL rewriting

**URL:** <https://www.ruby-forum.com/t/url-rewriting/102461>\
**Category:** Rails\
**Created:** [February 8, 2006, 5:35pm UTC](https://www.ruby-forum.com/t/url-rewriting/102461 "2006-02-08T17:35:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [February 8, 2006, 5:35pm UTC](https://www.ruby-forum.com/t/url-rewriting/102461/1 "2006-02-08T17:35:43Z")

</div>

Here is the scenario I am trying to achieve. Basically, I want to run  
the action “show” from my controller, without adding the “show/id”.

Standard:  
[http://www.domain.com/controllerName/show/id](http://www.domain.com/controllerName/show/id)

I would like:  
[http://www.domain.com/controllerName/randomstring](http://www.domain.com/controllerName/randomstring) (where randomstring is  
a  
field in my model/table, that is equivalent to a GUID → and unique).

I’m confused at how this would be possible, because you normally would  
create an action in the controller, that is then used in the url.  
Would this be a URL rewrite that would need to be added to .htaccess?  
If so, the I would have to some how change the “show” action to not  
use “id”?

Thanks for any help you can provide.

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [February 8, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/url-rewriting/102461/2 "2006-02-08T17:42:07Z")

</div>

I believe you don’t need URL rewriting for this.

I was trying to something similar so instead of  
[http://domain.com/post/id](http://domain.com/post/id)  
it will use [http://domain/post/title](http://domain/post/title)

and I ended up using something like:

map.connect ‘post/:mytitle’, :controller =\> “yourController”, :action  
=\> ‘show’

Look around in routes.rb file.

Hope this helps.

Frank

Kevin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote: Here is the scenario I am trying to  
achieve. Basically, I want to run  
the action “show” from my controller, without adding the “show/id”.

Standard:  
[http://www.domain.com/controllerName/show/id](http://www.domain.com/controllerName/show/id)

I would like:  
[http://www.domain.com/controllerName/randomstring](http://www.domain.com/controllerName/randomstring) (where randomstring is  
a  
field in my model/table, that is equivalent to a GUID → and unique).

I’m confused at how this would be possible, because you normally would  
create an action in the controller, that is then used in the url.  
Would this be a URL rewrite that would need to be added to .htaccess?  
If so, the I would have to some how change the “show” action to not  
use “id”?

Thanks for any help you can provide.

–  
Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2acd7d/32.png) [@kevin](https://www.ruby-forum.com/u/kevin)\
**Post date:** [February 8, 2006, 5:48pm UTC](https://www.ruby-forum.com/t/url-rewriting/102461/3 "2006-02-08T17:48:57Z")

</div>

Hi Frank,

That looks like exactly what I was looking for. I will give it a try.

Thanks for your help…

Kevin

softwareengineer 99 wrote:

> I believe you don’t need URL rewriting for this.
> 
> I was trying to something similar so instead of  
> [http://domain.com/post/id](http://domain.com/post/id)  
> it will use [http://domain/post/title](http://domain/post/title)
> 
> and I ended up using something like:
> 
> map.connect ‘post/:mytitle’, :controller =\> “yourController”, :action  
> =\> ‘show’
> 
> Look around in routes.rb file.
> 
> Hope this helps.
> 
> Frank
