# Redirect urls

**URL:** <https://www.ruby-forum.com/t/redirect-urls/223707>\
**Category:** NGINX\
**Created:** [October 15, 2012, 5:57am UTC](https://www.ruby-forum.com/t/redirect-urls/223707 "2012-10-15T05:57:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 15, 2012, 5:57am UTC](https://www.ruby-forum.com/t/redirect-urls/223707/1 "2012-10-15T05:57:47Z")

</div>

I’m porting a .asp application over to something else, and I need to  
re-write the following url pattern:

[www.example.com/posts/get\_post.asp?post\_id=123](http://www.example.com/posts/get_post.asp?post_id=123)

to

[www.example.com/posts/123](http://www.example.com/posts/123)

How can I do that?

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [October 15, 2012, 6:45am UTC](https://www.ruby-forum.com/t/redirect-urls/223707/2 "2012-10-15T06:45:06Z")

</div>

On Mon, Oct 15, 2012 at 10:56 AM, S Ahmed [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m porting a .asp application over to something else, and I need to  
> re-write the following url pattern:
> 
> [www.example.com/posts/get\_post.asp?post\_id=123](http://www.example.com/posts/get_post.asp?post_id=123)
> 
> to
> 
> [www.example.com/posts/123](http://www.example.com/posts/123)

location = /posts/get\_post.asp {  
return 301 /posts/$arg\_post\_id;  
}

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [October 15, 2012, 4:27pm UTC](https://www.ruby-forum.com/t/redirect-urls/223707/3 "2012-10-15T16:27:05Z")

</div>

So when nginx responds with a 301, is that an additional rountrip for  
the  
user?

Could I somehow maintain the url for the client, but internally re-write  
it  
to the updated url so my web application can handle it correctly?

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [October 15, 2012, 6:17pm UTC](https://www.ruby-forum.com/t/redirect-urls/223707/4 "2012-10-15T18:17:32Z")

</div>

On Mon, Oct 15, 2012 at 9:26 PM, S Ahmed [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So when nginx responds with a 301, is that an additional rountrip for the  
> user?
> 
> Could I somehow maintain the url for the client, but internally re-write it  
> to the updated url so my web application can handle it correctly?

rewrite ^ /posts/$arg\_post\_id;

---

<div class="post-metadata">

**Author:** ![S\_Ahmed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@S\_Ahmed](https://www.ruby-forum.com/u/S_Ahmed)\
**Post date:** [October 15, 2012, 9:56pm UTC](https://www.ruby-forum.com/t/redirect-urls/223707/5 "2012-10-15T21:56:41Z")

</div>

so like this:

location = /posts/get\_post.asp {  
rewrite ^ /posts/$arg\_post\_id;  
}

correct?
