So your are working on a website on your local dev machine and maybe you want to run the website in Local IIS with a custom url. You don't want to run it as an application under the default website, you want it to be a website on it's own with a custom url. So you need to get that custom url to point to your localhost, basically 127.0.0.1

Old Way

Here is how you would normally do it by adding the url to the host file:

  1. Open Notepad as an administrator by right-clicking on it in the start menu and choosing 'Run as administrator'
    Click File > Open > C:\Windows\System32\drivers\etc

  2. Above the open button where it says TextDocuments (*.txt) change it to All Files (*.*)

  3. Then select the file named hosts and click on Open.

  4. Add a new line at the bottom of the file like this:
    127.0.0.1 codeshare.local

  5. The number on the left is the IP address where you want that url to point to. Leave it as 127.0.0.1 so it points to your machine. the address on the right is the address of your site. Notice that it doesn't need http:// in front of if here.

  6. Save the file.

New Way

Here is how you can do it now.

  1. Just think of a url which ends with .localtest.me like this:
codeshare.localtest.me

How does it work?

Some kind person has set up the domain localtest.me and set the DNS for *.localtest.me to point to 127.0.0.1, so basically it just points to your local machine.

Go ahead and try it.

To test it out, you could use the command line to do the following:

ping anything.localtest.me

You will see it replies from 127.0.0.1. So there is no need to edit your hosts file any more for local development urls.

I was really pleased when I found this out from one of my YouTube subscribers, so I thought I should share it with you.

Please share this with others to let them know about it.

SECURITY NOTE:

Thanks to brunty and cemerson from the Tech Nottingham Slack Group for pointing out some security concerns with this. They were concerned that the domain owner could point the traffic to a malware site or something like that, which is a valid point, but I trust the person who registered the domain.

If you don't trust the person who set this domain up, you could always register a domain for yourself and point the subdomains to 127.0.0.1 to achieve the same thing.

Want to learn more?

Take a look at these videos I hand picked for you:

Want to thank me?

If I've helped you out and you want to thank me, why not buy me a coffee?

Paul Seal

A .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Web: codeshare.co.uk

Comments

Share Top