Setting a Localhost Alias as a Keyboard Shortcut in Chrome
If you're a web developer or a frequent user of localhost, you may find it tedious to type out the full address every time you want to access a local server. A quicker way to do this is to set up a localhost alias and assign it a keyboard shortcut in Google Chrome. This will allow you to access your local server with just a few keystrokes, saving you time and effort.
What is a Localhost Alias?
A localhost alias is a custom name that you can assign to the localhost address (http://localhost) on your computer. This can be anything you want, such as localhost, local, or dev. Once you've set up a localhost alias, you can use it to access your local server instead of typing out the full http://localhost address.
Setting Up a Localhost Alias
To set up a localhost alias, you'll need to edit your hosts file. The location of the hosts file varies depending on your operating system:
- Windows:
C:\Windows\System32\drivers\etc\hosts - Mac:
/private/etc/hosts - Linux:
/etc/hosts
To edit the hosts file, you'll need to open it in a text editor with administrator privileges. Once you have the file open, add a new line at the end with the following format:
127.0.0.1 [localhost alias]For example, to set up a localhost alias of local, you would add the following line:
127.0.0.1 localSave the hosts file and flush your DNS cache to apply the changes. On Windows, you can do this by opening a command prompt and running the following command:
ipconfig /flushdnsOn Mac and Linux, you can flush the DNS cache by running the following command in a terminal:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderSetting a Keyboard Shortcut for Your Localhost Alias in Chrome
Now that you have a localhost alias set up, you can assign it a keyboard shortcut in Chrome. To do this, follow these steps:
- Open Chrome and go to
chrome://extensions/ - Click the “Developer mode” toggle in the top right corner
- Click the “Load unpacked” button and select the
manifest.jsonfile for the Custom Keyboard Shortcut extension - In the extension options, add a new shortcut with the following format:
{“keys”: [“”], “command”: “open-url”, “url”: “http://[localhost alias]”} For example, to set up a shortcut of Ctrl+Shift+L for the local alias, you would use the following format:
{“keys”: [“Ctrl+Shift+L”], “command”: “open-url”, “url”: “http://local”}Save the extension options and your localhost alias will now be accessible with the keyboard shortcut you specified.
In this article, we covered the following topics:
- What is a localhost alias and how to set it up
- How to set a keyboard shortcut for your localhost alias in Chrome using the Custom Keyboard Shortcut extension