# Rewrite rule to remove trailing dot from hostname

**URL:** <https://www.ruby-forum.com/t/rewrite-rule-to-remove-trailing-dot-from-hostname/146957>\
**Category:** NGINX\
**Created:** [August 27, 2008, 2:11am UTC](https://www.ruby-forum.com/t/rewrite-rule-to-remove-trailing-dot-from-hostname/146957 "2008-08-27T02:11:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![esquilax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@esquilax](https://www.ruby-forum.com/u/esquilax)\
**Post date:** [August 27, 2008, 2:11am UTC](https://www.ruby-forum.com/t/rewrite-rule-to-remove-trailing-dot-from-hostname/146957/1 "2008-08-27T02:11:32Z")

</div>

Here’s the issue:

Right now users can browse my site via either “http://.com” or  
“http://.com.”. Notice the trailing dot. So because of some  
flash security issues I want to redirect the hostname with the trailing  
dot to my regular hostname. Should be easy, right?

I’ve tried a bunch of things, and it appears that $host doesn’t include  
the trailing dot. But if it doesn’t, does anything?

```
if ($host ~ "<host_name>.com\." ){
  rewrite ^(.*) http://<%= http_host_name %>$1 permanent;
}

```

I’ve also tried

```
if ($host ~ "\.$" ){
  rewrite ^(.*) http://<%= http_host_name %>$1 permanent;
}

```

And a number of other things. Any ideas would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![esquilax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@esquilax](https://www.ruby-forum.com/u/esquilax)\
**Post date:** [August 27, 2008, 9:13am UTC](https://www.ruby-forum.com/t/rewrite-rule-to-remove-trailing-dot-from-hostname/146957/2 "2008-08-27T09:13:45Z")

</div>

On Wed, Aug 27, 2008 at 02:11:32AM +0200, Andrew Grim wrote:

> ```
> }
> 
> ```
> 
> I’ve also tried
> 
> ```
> if ($host ~ "\.$" ){
> rewrite ^(.*) http://<%= http_host_name %>$1 permanent;
> }
> 
> ```
> 
> And a number of other things. Any ideas would be greatly appreciated!

The $host has no trailing dot, use original $http\_host instead.

---

<div class="post-metadata">

**Author:** ![esquilax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@esquilax](https://www.ruby-forum.com/u/esquilax)\
**Post date:** [August 27, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/rewrite-rule-to-remove-trailing-dot-from-hostname/146957/3 "2008-08-27T20:20:10Z")

</div>

Igor S. wrote:

> On Wed, Aug 27, 2008 at 02:11:32AM +0200, Andrew Grim wrote:
> 
> > ```
> > }
> > 
> > ```
> > 
> > I’ve also tried
> > 
> > ```
> > if ($host ~ "\.$" ){
> > rewrite ^(.*) http://<%= http_host_name %>$1 permanent;
> > }
> > 
> > ```
> > 
> > And a number of other things. Any ideas would be greatly appreciated!
> 
> The $host has no trailing dot, use original $http\_host instead.

Perfect, thanks!
