# A Bug

**URL:** <https://www.ruby-forum.com/t/a-bug/200257>\
**Category:** NGINX\
**Created:** [December 7, 2010, 10:40pm UTC](https://www.ruby-forum.com/t/a-bug/200257 "2010-12-07T22:40:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 7, 2010, 10:40pm UTC](https://www.ruby-forum.com/t/a-bug/200257/1 "2010-12-07T22:40:23Z")

</div>

I redirect the \*.yanbao360.com to [www.yanbao360.com](http://www.yanbao360.com) use the  
configuration below.

> [@](#):
>
> location / {  
> if ($host != ‘[www.yanbao360.com](http://www.yanbao360.com)’) {  
> rewrite ^(.\*)$ [http://www.yanbao360.com$1](http://www.yanbao360.com$1);  
> }  
> }

everything is ok except three case return 200 not 302

how to duplicate (nginx 0.8.x ~ 0.9.x)

> [@](#):
>
> telnet [yanbao360.com](http://yanbao360.com) 80

then paste one of these text

GET / HTTP/1.1  
Host: [WWW.yanbao360.com](http://WWW.yanbao360.com)

GET / HTTP/1.1  
Host: [www.yanbao360.com](http://www.yanbao360.com).

GET / HTTP/1.1  
Host: [WWW.yanbao360.com](http://WWW.yanbao360.com).

press enter twice, you will get nginx return 200 OK

Posted at Nginx Forum:

> **[A Bug](https://forum.nginx.org/read.php?2,156560,156560#msg-156560)**
>
> I redirect the \*.yanbao360.com to www.yanbao360.com use the configuration below. \[quote\] location / { if ($host != 'www.yanbao360.com') { rewrite ^(.\*)$ http://www.yanbao360.com$1; } } \[/quote\] ev

---

<div class="post-metadata">

**Author:** ![f3zz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@f3zz](https://www.ruby-forum.com/u/f3zz)\
**Post date:** [December 8, 2010, 2:27am UTC](https://www.ruby-forum.com/t/a-bug/200257/2 "2010-12-08T02:27:58Z")

</div>

Hello!

On Tue, Dec 07, 2010 at 04:39:32PM -0500, f3zz wrote:

> Host: [WWW.yanbao360.com](http://WWW.yanbao360.com)
> 
> GET / HTTP/1.1  
> Host: [www.yanbao360.com](http://www.yanbao360.com).
> 
> GET / HTTP/1.1  
> Host: [WWW.yanbao360.com](http://WWW.yanbao360.com).
> 
> press enter twice, you will get nginx return 200 OK

Variable $host contains normalized host name, and all of the above  
forms are normalized into ‘[www.yanbao360.com](http://www.yanbao360.com)’ in $host variable as  
they are equivalent.

Case-insensitive matching of hostnames is explicitly required by  
RFC2616[1]. And fully qualified domain name may contain trailing  
“.” if it is necessary to distinguish between the complete domain  
name and some local domain[2].

[1] [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](http://tools.ietf.org/html/rfc2616#section-3.2.3)  
[2] [RFC 3986: Uniform Resource Identifier (URI): Generic Syntax | RFC Editor](http://tools.ietf.org/html/rfc3986#section-3.2.2)

If you want to check Host header exactly as sent by client - you  
may use $http\_host variable instead. There are some caveats  
though:

1. Redirection to equivalent URL may cause problems, as it’s  
basically identical to infinite redirection loop.

2. You’re likely to see some browsers sending port in Host header  
(“www.yanbao360.com:80”) even if it’s default one.

3. Some requests may use absolute URL in request line, then Host  
header must be ignored and host portion of URL used instead  
(though this shouldn’t happen with HTTP/1.1 clients).

Maxim D.

---

<div class="post-metadata">

**Author:** ![f3zz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@f3zz](https://www.ruby-forum.com/u/f3zz)\
**Post date:** [December 8, 2010, 6:36am UTC](https://www.ruby-forum.com/t/a-bug/200257/3 "2010-12-08T06:36:14Z")

</div>

On 12/07/2010 10:26 PM, Maxim D. wrote:

> If you want to check Host header exactly as sent by client - you  
> may use $http\_host variable instead. There are some caveats  
> though:..

Also check these examples;

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

---

<div class="post-metadata">

**Author:** ![f3zz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@f3zz](https://www.ruby-forum.com/u/f3zz)\
**Post date:** [December 8, 2010, 11:04pm UTC](https://www.ruby-forum.com/t/a-bug/200257/4 "2010-12-08T23:04:15Z")

</div>

Thanks for the helpful information. nginx is a great software.

Posted at Nginx Forum:

> **[Re: A Bug](https://forum.nginx.org/read.php?2,156560,156976#msg-156976)**
>
> I redirect the \*.yanbao360.com to www.yanbao360.com use the configuration below. \[quote\] location / { if ($host != 'www.yanbao360.com') { rewrite ^(.\*)$ http://www.yanbao360.com$1; } } \[/quote\] ev

---

<div class="post-metadata">

**Author:** ![f3zz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@f3zz](https://www.ruby-forum.com/u/f3zz)\
**Post date:** [December 8, 2010, 8:39am UTC](https://www.ruby-forum.com/t/a-bug/200257/5 "2010-12-08T08:39:01Z")

</div>

On Tue, Dec 07, 2010 at 04:39:32PM -0500, f3zz wrote:

> everything is ok except three case return 200 not 302

Apart Maxim’s technical explantaion, you should use:

> **[Converting rewrite rules](http://nginx.org/en/docs/http/converting_rewrite_rules.html)**

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
