# Get server url

**URL:** <https://www.ruby-forum.com/t/get-server-url/116221>\
**Category:** Rails\
**Created:** [October 3, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/get-server-url/116221 "2007-10-03T16:58:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 3, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/get-server-url/116221/1 "2007-10-03T16:58:44Z")

</div>

Hi all,

How do i get the server url? Much like the PHP function  
$\_SERVER[“REQUEST\_URI”]

Regards,  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 3, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/get-server-url/116221/2 "2007-10-03T17:12:14Z")

</div>

On 10/3/07, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,
> 
> How do i get the server url? Much like the PHP function  
> $\_SERVER[“REQUEST\_URI”]

You can get it your controller through

request.request\_uri

or in your view through

controller.request.request\_uri

All the CGI-style variables are available through request.env as well,  
so this works:

request.env[‘REQUEST\_URI’]

But I wonder why you want it? You normally work with the Rails routing  
system and don’t deal with the details of the request URI. What are  
you trying to accomplish?

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 3, 2007, 5:18pm UTC](https://www.ruby-forum.com/t/get-server-url/116221/3 "2007-10-03T17:18:05Z")

</div>

Many thanks for the fast reply.

The request.env[‘REQUEST\_URI’] only returns the path eg:  
[http://localhost:3000/user](http://localhost:3000/user) I get /user . Iactually want  
[http://localhost:3000/](http://localhost:3000/)  
I can do this via request.protocol()+request.request\_uri() but I  
wonder if there is a single method that can do this.

I need this for mail sending. I’m creating a user activation system  
that wan run on multiple domains. When I send out a mail the user has  
to click alink to activate it. Ofcourse this link is dependant on the  
domain the site is hosted on.

Regards,  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [October 3, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/get-server-url/116221/4 "2007-10-03T18:20:23Z")

</div>

On 10/3/07, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I need this for mail sending. I’m creating a user activation system  
> that wan run on multiple domains. When I send out a mail the user has  
> to click alink to activate it. Ofcourse this link is dependant on the  
> domain the site is hosted on.

Use url\_for with :only\_path set to false to generate full url’s

activate\_link = url\_for({:only\_path =\> false}, :controller =\>  
‘account’, :action =\> ‘activate’, :id =\> @user)

Or, if you have a named route for activation, these generate full  
url’s by default:

activate\_link = activate\_url(:id =\> @user)
