Is there any possibility to add a prefix before localhost?

My question is that I want to add a prefix before localhost for my project url (ie. "dev.localhost/project/default.htm"). This is for an ASP.NET application running in IIS.

closed as off topic by user7007, Walter, yannis Dec 8 '12 at 13:22

Questions on Software Engineering Stack Exchange are expected to relate to software engineering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

  • This question is probably better suited on StackOverflow as it deals with an implementation issue and not a design/architecture issue. Please don't reask you question on SO, this question can be migrated. – Walter Dec 8 '12 at 13:00
  • 2
    Ghost Answer this is a lot more appropriate for SO than us, as @walter already mentioned, but you appear to be question blocked on SO. Please don't post off topic questions on Programmers to circumvent your ban on SO. – yannis Dec 8 '12 at 13:24

Yes, this is possible, depending on the webserver you use.

For Apache you can create a virtual host config.

You can do it like this:


   DocumentRoot "C:\project1"
   ServerName dev1.localhost

   DocumentRoot "C:\project2"
   ServerName dev2.localhost

See also: http://www.apptools.com/phptools/virtualhost.php

Further, you'll hav to put an entry in your hosts file to redirect to dev1.localhost dev2.localhost
  • thanks for your nice suggestion. I updated my post and now give your suggestions. – Ghost Answer Dec 8 '12 at 11:58
  • 1
    Works perfectly in IIS, too. Just edit the site's bindings, add a new binding with type "http", ip address "All Unassigned", port 80, host name "dev1.localhost"; and add the host to c:\windows\system32\drivers\etc\hosts as – Carson63000 Dec 8 '12 at 19:37

I'm sorry, but the short answer is no. A URL has a specific defined format of:


so in your example, the protocol is implied as HTTP, there is no username, the host is localhost, its using port 80, the default for HTTP, and the file path is /project/default.htm. It makes more sense to use the path part to diferentiate the different project locations.

The longer answer, is yes, but this depends on how you are hosting your project URLs. The HTTP protocol identifies the host part of the URL when it makes the request to the server. Some Web servers then use this to serve multiple sites from the same computer. (think web hosting companies running multiple customer websites on a single server). This means you could create multiple hostnames for your computer, and then configure the webserver to reference different projects based on the hostname used to connect to. not sure that dev.localhost is a good idea, dev-localhost may well work better, with an entry in /etc/hosts to identify its ip address as

  • 2 down votes, and no explanations of why... How is that going to help people understand what is so wrong about this answer? – Michael Shaw Dec 8 '12 at 11:46
  • 2
    -1, since the answer is wrong. The answer by Falcon shows that what is asked is possible in Apache. I'm pretty sure that IIS would support this as well. – Arseni Mourzenko Dec 8 '12 at 12:09
  • No idea why you started out saying "the short answer is no", when in fact the short answer, the long answer, and every other answer is "yes". The second half of your reply is correct: why did you mess it up by saying "no" initially, and implying that "dev.localhost" is not a valid internal hostname? – Carson63000 Dec 8 '12 at 19:39
  • From the way the original question was worded, it seemed likely the poster did not understand that the first part was actually a host name, otherwise the question would have been "how can I give my host multiple names". The short answer is corrrect. - You cannot prefix the hostname in a URL with arbitary text. The issue with the long answers is that it may not be possible to implement these changes if you need to host remotely in the future on an ISP. – Michael Shaw Dec 9 '12 at 15:56

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