# Problem with requests that have a . in the end of the domain

**URL:** <https://www.ruby-forum.com/t/problem-with-requests-that-have-a-in-the-end-of-the-domain/176561>\
**Category:** NGINX\
**Created:** [October 2, 2009, 5:46am UTC](https://www.ruby-forum.com/t/problem-with-requests-that-have-a-in-the-end-of-the-domain/176561 "2009-10-02T05:46:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [October 2, 2009, 5:46am UTC](https://www.ruby-forum.com/t/problem-with-requests-that-have-a-in-the-end-of-the-domain/176561/1 "2009-10-02T05:46:10Z")

</div>

hi

i am currently experiencing some strange behavior if a user requests  
our domain with a . in the end of the domain. the actual problem is  
that our php code can’t really get along with that . in the end of the  
domain. so i tried creating an nginx rule that fixes this by doing a  
redirect to the correct domain. i tried multiple things, first i just  
left our actual production vhost untouched and added an additional one  
with the same server\_name but with a . in the end of the domain, like  
this:

server {  
server\_name mydomain;  
…  
}

server {  
server\_name mydomain.;

rewrite . http://mydomain$request\_uri permanent;  
}

but i found out that the requests never reach the vhost mydomain., i  
also tried to switch the order of those two, but all requests always  
go to the vhost mydomain without .

then another thing i tried was to catch the bad request based on the  
$host variable like this:

server {  
if ($host ~ “^mydomain.$”)  
{  
rewrite . http://mydomain$request\_uri permanent;  
}  
}

but now when i check the rewrite log i see that this $host variable  
doesn’t contain the . even if the request did. this means i request  
[http://mydomain](http://mydomain). in my browser and in the rewrite log i see:

2009/10/01 12:23:55 [notice] 8238#0: \*3 “^mytdomain.$” does not match  
“mydomain”, client: 192.168.56.1, server: mydomain, request: “GET /  
HTTP/1.1”, host: “mydomain.”

i am sure that the browser does not parse this . out, because the php  
can see it. and in the end of the above log line you can also see  
host: “mydomain.”.

does anybody maybe have an idea what else i could do to make sure that  
[http://mydomain](http://mydomain). gets redirected to [http://mydomain](http://mydomain)?

thanks a lot for help

mauro

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [October 2, 2009, 7:14am UTC](https://www.ruby-forum.com/t/problem-with-requests-that-have-a-in-the-end-of-the-domain/176561/2 "2009-10-02T07:14:33Z")

</div>

On Fri, Oct 02, 2009 at 11:34:57AM +0800, Mauro Stettler wrote:

> ```
> rewrite . http://mydomain$request_uri permanent;
> 
> ```
> 
> i am sure that the browser does not parse this . out, because the php  
> can see it. and in the end of the above log line you can also see  
> host: “mydomain.”.
> 
> does anybody maybe have an idea what else i could do to make sure that  
> [http://mydomain](http://mydomain). gets redirected to [http://mydomain](http://mydomain)?

Yes, server\_name ignores trailing dot. The dot is removed from $host  
too.  
Therefore you should unchanged $http\_host:

server {

- if ($host ~ “^mydomain.$”)

- if ($http\_host = mydomain.)  
{

- 

```
rewrite . http://mydomain$request_uri permanent;

```

- 

```
rewrite . http://mydomain$request_uri? permanent;

```

}  
}

Also if you use proxy for PHP, then you may edit “Host” header:  
proxy\_set\_header Host $host;

however, you can do the same with FastCGI.

---

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [October 2, 2009, 7:22am UTC](https://www.ruby-forum.com/t/problem-with-requests-that-have-a-in-the-end-of-the-domain/176561/3 "2009-10-02T07:22:10Z")

</div>

thanks a lot, that works perfectly, even with my old version 0.6.35

mauro

2009/10/2 Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
