8

I am running an IIS 7.5 site that serves up content for http://www.foo.com/

I've been asked to properly route http://www.foo.com./ (note the trailing dot). If you hit that page now, you'll get an IIS error:

Bad Request - Invalid Hostname

HTTP Error 400. The request hostname is invalid.

This happens even for http://www.microsoft.com. I have seen some sites route trailing periods successfully (like http://www.amazon.com./), but it looks like most of those were using Apache, not IIS.

I added a host header in IIS for www.foo.com. which is allowed. However, it won't let you start the site. It won't start and pops up a message box saying:

Value does not fall within the expected range.

Does anyone know how to serve up domains with trailing dots in IIS?

1

5 Answers 5

5

The trailing dot is an absolutely legal part of the hostname - it's just that it's normally invisible because it's implicit in DNS. If the trailing dot is present it's called a "Fully Qualified" Domain Name (FQDN).

Note that on the wire DNS always deals in FQDNs.

§3.2.2 of RFC 3976 (the definition for URI syntax) says this (my emphasis):

A host identified by a registered name is a sequence of characters usually intended for lookup within a locally defined host or service name registry, though the URI's scheme-specific semantics may require that a specific registry (or fixed name table) be used instead. The most common name registry mechanism is the Domain Name System (DNS). A registered name intended for lookup in the DNS uses the syntax defined in Section 3.5 of [RFC1034] and Section 2.1 of [RFC1123]. Such a name consists of a sequence of domain labels separated by ".", each domain label starting and ending with an alphanumeric character and possibly also containing "-" characters. The rightmost domain label of a fully qualified domain name in DNS may be followed by a single "." and should be if it is necessary to distinguish between the complete domain name and some local domain.

File a bug report with MS.

4
  • 1
    I agree that MS is in the wrong here, just trying to find out if there might be a workaround.
    – Aaron D
    Aug 11, 2010 at 16:20
  • id love a workaround too (just like with wildcard host headers), but MS seems to love to ignore this sort of thing. Feb 3, 2012 at 6:18
  • The trailing dot is not legal, per RFC 1718. The "." is implied, the hostname is implicitly an FQDN. The URL should have failed the browser validation, but most browsers seem to not do this correctly.
    – benc
    Nov 9, 2012 at 22:02
  • 2
    WTH does the IETF Tao have to do with FQDNs? At least quote the right RFC, and one that obsoletes the one I referenced which is the definitive RFC for this. (hint - there isn't one).
    – Alnitak
    Nov 9, 2012 at 22:06
2

This is effectively a bug in IIS7+, apparently with no workarounds. It is affecting me as well. Please go vote up the request for MS to fix this:

https://connect.microsoft.com/WindowsServerFeedback/feedback/details/648242/trailing-dot-in-fqdn-causing-bad-request-invalid-hostname

4
  • This is not a bug, the URL is invalid. An FQDN is literally written as a dot-terminated string, however in URLs, the FQDN is assumed (no partially qualified domains, and no trailing dot). In fact your browser should not be sending this.
    – benc
    Nov 9, 2012 at 16:52
  • 3
    @benc you are wrong on both counts - unqualified domain names and the trailing dot are both absolutely permitted in a URI. See my updated answer for chapter and verse. Kindly reverse your incorrect downvote!
    – Alnitak
    Nov 9, 2012 at 19:14
  • @benc If a URL was assumed to always implicitly specify an FQDN, URLs such as myinternalmachine/foo wouldn't work, because if it was always interpreted as an FQDN, a trailing dot would be applied before resolving, and "myinternalmachine." is not typically resolvable in DNS (to make it so I would essentially need to add what is essentially a new "root" domain in my private DNS server. Mar 20, 2013 at 9:51
  • and besides: even if it were not "legal", I have inbound links that are accidently formatted in this way, and I would like to redirect them to the right page. currently, iis barfs too early in the process and I don't have the chance to "fix" these bad urls via redirects etc. Mar 21, 2013 at 17:01
0

This issue is discussed on Microsoft forums here and is seen as a change in behaviour between IIS 6 and 7.

This site here provides a work-around to re-write the url on the IIS side.

The config change required for various web-servers is reproduced below in case the site above ever goes away.

Apache (.htaccess)
RewriteCond %{HTTP_HOST} !^domain\.zone$
RewriteRule ^(.*)$ http://domain.zone/$1 [L,R=301]

Nginx (nginx.conf)
if ($http_host != 'domain.zone') {
    return 301 http://domain.zone$request_uri;
}

IIS (web.config)
<httpRuntime relaxedUrlToFileSystemMapping="true"/>
<rule name="point" stopProcessing="true"> <match url="^(.*)\.$" />
    <action type="Redirect" url="{R:1}" redirectType="Temporary" /> 
</rule>
2
  • I tried the IIS workaround you supplied but I still get the same result: 400 bad request. Have you actually tried the workaround to verify it? I don't think IIS is transferring control to the rewrite rules before kicking out a 400 error.
    – Aaron D
    Jul 30, 2013 at 0:36
  • This isn't a workaround for the issue posted here. This is simply a way to canonicalise such a request (which reportedly wasn't happening in the first place on IIS 7.5)
    – MrWhite
    Aug 24, 2019 at 2:25
-1

I am sure that there is a bug somewhere but the question is what the bug is.

I think that the bug is that IIS allows you to set a host header with a trailing ".". The host header is not the same thing as a FQDN. The host header is meant to match the Host directive in the HTTP request:

GET / HTTP/1.0
HOST: www.doilooklikeicare.com

It is certainly valid in the URL typed in to the browser eg: http://www.doilooklikeicare.com./default.aspx as this is resolved to find out WHERE to send the request.

Try removing the trailing dot in the host header and it should work OK. You will still be able to use it in the URL.

Hope this helps

Jonathan

3
  • The name is resolved, IIS handles your request, but you get a 400 Invalid Request when you click the link you provided. That is exactly what I want to avoid. I can serve up www.foo.com without issue. I cannot seve www.foo.com.
    – Aaron D
    Aug 16, 2010 at 15:51
  • 1
    sorry this answer is completely wrong. apparently IIS is snatching the trailing dot url before it can be handled anywhere else. If i coudl add an extra host header with the dot, i would... Feb 3, 2012 at 6:17
  • The host header is made by the browser, not by the server. The server error is the server rejecting the host header.
    – benc
    Nov 9, 2012 at 22:03
-1

The browser is at fault. It should not accept a trailing dot in the hostip (hostname) portion of the URL.

Specifically, for FF and other mozilla-based browsers:

Bug 124565 - DNS: URL: FQDN usage in "hostip"

From a design perspective, the networking library (necko) should be rejecting this, but the docshell (the user-friendly part) should probably trap aa user-inputed string, and do fix-up (remove the ".", and clean up the Host: header).

Incidentally, necko also has a problem where it is fqdn-lazy, it doesn't stick the "." on the end of the fqdn when it sends the request to the resolver, which makes every fqdn treated by the local-resolver's pqdn logic.

1
  • 4
    I disagree. First, a trailing dot is a legal part of a hostname - look at the RFC posted by @Alnitak. Second - this is not a browser problem but rather a problem with the server (IIS). No request with a trailing dot will succeed to an IIS-hosted website bound to a domain name, regardless of the browser used.
    – Aaron D
    Dec 17, 2012 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.