Rewrite rule to remove trailing dot from hostname

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!

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.

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!