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.
2
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:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "C:project1"
ServerName dev1.localhost
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "C:project2"
ServerName dev2.localhost
</VirtualHost>
See also: http://www.apptools.com/phptools/virtualhost.php
Further, you’ll hav to put an entry in your hosts file to redirect to 127.0.0.1.
127.0.0.1 dev1.localhost
127.0.0.1 dev2.localhost
2
I’m sorry, but the short answer is no. A URL has a specific defined format of:
[protocol]:[user@]host:[port]/[path]
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 127.0.0.1
4