I recently found out the hard way that the underscore character “_” can be problematic within URLs, particularly with Internet Explorer. Here is why…

(FYI, my testing was done with IE 9)

First of all, the underscore character is a perfectly acceptable character in a URL. Web browsers can deal with it fine in most circumstances. However, IE seems to dislike the underscore when it is in a domain or subdomain name, for instance www.my_site.com or test_site.mysite.com. Will it work? Under general circumstances it might. The problem shows up when you need a cookie for the site, which most sites do, especially if you are using cookies as part of your authentication scheme. IE can’t create cookies when the domain or subdomain name has an underscore.

This doesn’t seem to be a problem for Firefox (I’ve tried it) and Chrome (so I have heard).

A note about SEO

Also, it is worth mentioning that the underscore is not a good choice in a URL if you are interested in SEO. That’s because some search engines like Google don’t consider the underscore a word separator. To Google, it reads a URL like “mysite.com/Page_About_Something_Cool” as mysite.com/pageaboutsomethingcool” which won’t help your rankings much. Bing is fine with the underscore but of course simply using a dash “-“ instead will keep both search engines happy.

I’ll close with a few examples

www.somesite.com/page-with-content good choice for a variety of browsers and search engines
mysubdomain.somesite.com/page-with-content good choice for a variety of browsers and search engines
www.some_site.com trouble for IE with cookies
sub_domain.somesite.com trouble for IE with cookies
www.somesite.com/page_with_content valid but bad for SEO with Google
Posted in Web.

4 thoughts on “Problems with Underscore in URLs

  1. According to relevant (e.g. RFC 1738) underscores are not legal in the domain name part of a URL. They can be present in the URI path that follows the domain name but are illegal in the domain or subdomain name parts.
    So your 3rd and 4th examples are technically illegal and so IE and other browsers should take issue with them.

  2. Pingback: Dew Drop – October 9, 2013 (#1,641) | Morning Dew

Leave a reply


<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>