# Remove www from url

**URL:** <https://www.ruby-forum.com/t/remove-www-from-url/161156>\
**Category:** Rails\
**Created:** [February 23, 2009, 11:08pm UTC](https://www.ruby-forum.com/t/remove-www-from-url/161156 "2009-02-23T23:08:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [February 23, 2009, 11:08pm UTC](https://www.ruby-forum.com/t/remove-www-from-url/161156/1 "2009-02-23T23:08:18Z")

</div>

So i have a rails app running in 2.0.2 and I would like to know if  
anyone can point me in the right direction on how to remove the www  
from the url. so if someone goes to [www.mydomain.com](http://www.mydomain.com) it will forward  
them to [mydomain.com](http://mydomain.com). I am running nginx, and thin, not sure if I do  
it in routes, in my nginx config file…? let me know if anyone has  
any insight to this. thanks.

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [February 24, 2009, 1:57am UTC](https://www.ruby-forum.com/t/remove-www-from-url/161156/2 "2009-02-24T01:57:23Z")

</div>

Dan P. wrote:

> So i have a rails app running in 2.0.2 and I would like to know if  
> anyone can point me in the right direction on how to remove the www  
> from the url. so if someone goes to [www.mydomain.com](http://www.mydomain.com) it will forward  
> them to [mydomain.com](http://mydomain.com). I am running nginx, and thin, not sure if I do  
> it in routes, in my nginx config file…? let me know if anyone has  
> any insight to this. thanks.

AFAIK this is purely a web server/DNS configuration issue and has  
nothing to do with Rails.

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [February 24, 2009, 2:04am UTC](https://www.ruby-forum.com/t/remove-www-from-url/161156/3 "2009-02-24T02:04:29Z")

</div>

The best way to do this is through a .htaccess file. That will do it  
with only 3 or 4 lines of code. A quick google search will get you  
what you need.

Sean McGilvray

Sent from my iPhone

On Feb 23, 2009, at 4:57 PM, Robert W.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [February 24, 2009, 3:31am UTC](https://www.ruby-forum.com/t/remove-www-from-url/161156/4 "2009-02-24T03:31:04Z")

</div>

On Mon, Feb 23, 2009 at 2:07 PM, Dan P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So i have a rails app running in 2.0.2 and I would like to know if  
> anyone can point me in the right direction on how to remove the www  
> from the url. so if someone goes to [www.mydomain.com](http://www.mydomain.com) it will forward  
> them to [mydomain.com](http://mydomain.com). I am running nginx, and thin, not sure if I do  
> it in routes, in my nginx config file…? let me know if anyone has  
> any insight to this. thanks.

Dan,

For apache:

RewriteCond %{HTTP\_HOST} ^www.example.com$ [NC]  
RewriteRule ^(.\*)$ [http://example.com$1](http://example.com$1) [R=301,L]

For nginx:

```
#rewrites http://www.example.com/foo => http://example.com/foo
if ($host ~* www\.(.*)) {
  set $host_without_www $1;
  rewrite ^(.*)$ http://$host_without_www$1 permanent; # $1

```

contains ‘/foo’, not ‘[www.example.com/foo](http://www.example.com/foo)’  
}

Good luck!

Cheers,  
Robby

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://robbyonrails.com/](http://robbyonrails.com/)  
[http://twitter.com/planetargon](http://twitter.com/planetargon)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [February 24, 2009, 3:36am UTC](https://www.ruby-forum.com/t/remove-www-from-url/161156/5 "2009-02-24T03:36:58Z")

</div>

On Mon, Feb 23, 2009 at 6:30 PM, Robby R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> For apache:

Forgot to mention that RewriteEngine needs to be turned on. Example: 🙂

```
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.planetargon\.com$ [NC]
    RewriteRule ^(.*)$ http://planetargon.com$1 [R=301,L]

```

> Â Â }

Cheers,  
Robby

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://robbyonrails.com/](http://robbyonrails.com/)  
[http://twitter.com/planetargon](http://twitter.com/planetargon)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
