problem with requests that have a . in the end of the domain
Mauro Stettler
mauro.stettler at gmail.com
Fri Oct 2 07:34:57 MSD 2009
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. 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. gets redirected to http://mydomain?
thanks a lot for help
mauro
More information about the nginx
mailing list