What are the allowed characters in a subdomain?
Asked Answered
A

5

90

What characters are you allowed to use in a subdomain?

Example: for someSub.example.com the someSub portion.

I know you can use letters, numbers, and hyphens, but what about other characters? Can _ (underscore) be used?

Albur answered 18/8, 2011 at 17:55 Comment(1)
tools.ietf.org/html/rfc1034Unfleshly
M
105

Letters (except stressed à), Numbers 0-9 and Hyphen.

http://en.wikipedia.org/wiki/Domain_name excerpt: Valid characters that can be used in a domain name are:

a-z
0-9
- but not as a starting or ending character
. as a separator for the textual portions of a domain name

From https://www.rfc-editor.org/rfc/rfc1035

Various objects and parameters in the DNS have size limits. They are listed below. Some could be easily changed, others are more fundamental.

labels          63 octets or less
names           255 octets or less
TTL             positive values of a signed 32 bit number.
UDP messages    512 octets or less
Morley answered 18/8, 2011 at 18:2 Comment(2)
Subdomains can be uppercase too.Bombe
@ShimmyWeitzhandler Domain names are case-insensitive, so a) upper-case characters are not allowed, but b) in searches, upper-case characters are mapped to lower-case.Poteat
R
34

According to this page, some top level domains now allow localized characters (not just a-z).

--------------------------------------------------------------------------------
| Top Level Domain |                    Allowed Characters                     |
--------------------------------------------------------------------------------
| .no              | áàäčçđéèêŋńñóòôöšŧüžæøå                                   |
| .se              | àáäåæçèéêëìíîïðñòóôöøùúüýþćčđěłńŋřśšţŧźžǎǐǒǔǥǧǩǯəʒ, plus Hebrew
| .dk              | äåæéöøü
| .is              | áéýúíóþæöð
| .it              | àâäèéêëìîïòôöùûüæœçÿ
| .fr              | àáâãäåæçèéêëìíîïñòóôõöùúûüýÿœ
| .nu              | àáâäåāæçèéêëēìíîïīðñŋòóôõöøōùúûüūýþÿ
| .be              | àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿœ
| .de              | àáâãäåāăąæçćĉċčďđèéêëēĕėęěŋðĝğġģĥħìíîïĩīĭįıĵķĸĺļľł
|                  | ñńņňòóôõöøōŏőœŕŗřśŝşšţťŧþùúûüũūŭůűųŵýÿŷźżž
| .as              | Same as .de
| .com             | Same as .de, plus Greek, Cyrillic, Chinese, Korean, etc.
| .net             | Same as .de, plus Greek, Cyrillic, Chinese, Korean, etc.
| .org             | áäåāąæćčéēėęģíīįķļłñńņðóöøōőŗśšúüūűųýźżžþ plus Cyrillic and Korean
| .info            | áäåāąæćčéēėęģíīįķļłńņðóöøōőŗśšúüūűųýźżžþ plus Korean
| .biz             | àáäåæéêíðñòóôöøúüýþ
--------------------------------------------------------------------------------

So, looks like we need to go back to the drawing board on that regex.

Romeliaromelle answered 11/3, 2014 at 8:17 Comment(2)
Note that these additional characters are only allowed in hostnames when they are encoded as internationalized domain names with only the standard set [A-Za-z0-9-] (see en.wikipedia.org/wiki/…).Residue
So your application must decide if it should allow non-ASCII characters (and convert to punycode automatically) or reject them.Negativism
E
25

Technically William is right, and only letters, numbers and hyphen (-) are allowed in subdomains.

However: in practice, you will see that underscore (_) will also work in all major browsers, but this is not guaranteed. Some providers and other services may not allow you to set it in DNS.

If you set a wildcard in DNS it will resolve, then then it is up to the actual application to take it or ignore it.

Ellanellard answered 8/5, 2013 at 1:7 Comment(3)
Bit late but this took me 2 days to figure out. DO NOT USE UNDERSCORES (_) IN YOUR SUBDOMAIN!!! Internet Explorer will not keep your sessions alive if you do!!!Placate
what an odd side-effect!Rustler
It's allowed more then one hipen in subdomain? es my-sub-domain-name.mydomain.comDrue
R
3

Ironically, the other answers to this questions are correct answers to the question "what are the legal characters for a hostname or primary domain", while the answers to the question "can (hostname) subdomains have an underscore" are correct answers to this question.

Residue answered 20/12, 2015 at 0:48 Comment(0)
J
3

For non-IDN domain names, the allowed characters per RFC 1035 are:

  • a-z
  • A-Z
  • 0-9
  • -
  • . – if part of a subdomain

Here's the full definition:

<domain> ::= <subdomain> | " "
<subdomain> ::= <label> | <subdomain> "." <label>
<label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
<ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
<let-dig-hyp> ::= <let-dig> | "-"
<let-dig> ::= <letter> | <digit>
<letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case
<digit> ::= any one of the ten digits 0 through 9

Specifically regarding upper/lower, domain names are case-insensitive. Here's a bit from RFC 1035 about that:

Note that while upper and lower case letters are allowed in domain names, no significance is attached to the case. That is, two names with the same spelling but different case are to be treated as if identical.

This answer addresses what is allowed for non-IDN domain names, and does not define behavior for a web browser, client application, or application server. If you've set up a wildcard (*) to route traffic somewhere, it's possible for a subdomain to contain characters beyond the set of a-zA-Z0-9-..

Journalistic answered 19/7, 2022 at 22:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.