# How to redirect user from www.myhostname.com to hostname.com

**URL:** <https://www.ruby-forum.com/t/how-to-redirect-user-from-www-myhostname-com-to-hostname-com/187222>\
**Category:** NGINX\
**Created:** [April 20, 2010, 4:12am UTC](https://www.ruby-forum.com/t/how-to-redirect-user-from-www-myhostname-com-to-hostname-com/187222 "2010-04-20T04:12:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![escavern](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f9b8f/32.png) [@escavern](https://www.ruby-forum.com/u/escavern)\
**Post date:** [April 20, 2010, 4:12am UTC](https://www.ruby-forum.com/t/how-to-redirect-user-from-www-myhostname-com-to-hostname-com/187222/1 "2010-04-20T04:12:06Z")

</div>

how to redirect user from [http://www.myhostname.com](http://www.myhostname.com) to  
[http://hostname.com](http://hostname.com) ??  
i mean if they access [http://www.myhostname.com](http://www.myhostname.com) he will be redirected to  
[http://hostname.com](http://hostname.com)  
pls help me

Posted at Nginx Forum:

> **[how to redirect user from www.myhostname.com to hostname.com](https://forum.nginx.org/read.php?2,76883,76883#msg-76883)**
>
> how to redirect user from http://www.myhostname.com to http://hostname.com ?? i mean if they access http://www.myhostname.com he will be redirected to http://hostname.com pls help me

---

<div class="post-metadata">

**Author:** ![escavern](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f9b8f/32.png) [@escavern](https://www.ruby-forum.com/u/escavern)\
**Post date:** [April 20, 2010, 4:23am UTC](https://www.ruby-forum.com/t/how-to-redirect-user-from-www-myhostname-com-to-hostname-com/187222/2 "2010-04-20T04:23:49Z")

</div>

Hello!

On Mon, Apr 19, 2010 at 10:11:13PM -0400, escavern wrote:

> how to redirect user from [http://www.myhostname.com](http://www.myhostname.com) to [http://hostname.com](http://hostname.com) ??  
> i mean if they access [http://www.myhostname.com](http://www.myhostname.com) he will be redirected to [http://hostname.com](http://hostname.com)  
> pls help me

server {  
listen 80;  
server\_name [www.myhostname.com](http://www.myhostname.com);

```
rewrite ^ http://hostname.com$request_uri? permanent;

```

}

Maxim D.

---

<div class="post-metadata">

**Author:** ![escavern](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f9b8f/32.png) [@escavern](https://www.ruby-forum.com/u/escavern)\
**Post date:** [April 20, 2010, 4:23am UTC](https://www.ruby-forum.com/t/how-to-redirect-user-from-www-myhostname-com-to-hostname-com/187222/3 "2010-04-20T04:23:49Z")

</div>

On 4/19/10 10:11 PM, escavern wrote:

> how to redirect user from [http://www.myhostname.com](http://www.myhostname.com) to [http://hostname.com](http://hostname.com) ??  
> i mean if they access [http://www.myhostname.com](http://www.myhostname.com) he will be redirected to [http://hostname.com](http://hostname.com)  
> pls help me

server {  
listen 80;  
server\_name [hostname.com](http://hostname.com);  
…  
}

server (  
listen 80;  
server\_name [www.myhostname.com](http://www.myhostname.com);  
rewrite ^ http://hostname.com$request\_uri? permanent;  
}

This assumes you want a redirect to the requested URI. If you want all  
requests to go to the index page for [http://hostname.com](http://hostname.com) omit  
“$request\_uri?” from the rewrite.

> Posted at Nginx Forum: [http://forum.nginx.org/read.php?2,76883,76883#msg-76883](http://forum.nginx.org/read.php?2,76883,76883#msg-76883)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Jim O.
