'How to add TLD to search exception in Safari
How can I add .locahost
to the list of TLDs that Safari will load — instead of searching — without supplying a protocol? Alternatively (or perhaps additionally), how do I get Safari to stop removing the http://
protocol from the URL?
I've been using project.localhost
to handle local development for a while, now that .dev
is no longer a viable development TLD. But I'm getting frustrated with Safari's default behavior. What I'd like to do is prevent Safari from submitting the domain name to the search engine.
Desired:
- enter
project.localhost
into address bar - browser loads
http://project.localhost
I would be satisfied with Safari not removing the http://
in the address bar, but I can't find a way to do that, either.
What actually happens:
- enter
project.localhost
into address bar - browser sends
project.localhost
to Duck Duck Go - user is tempted to test the ballistic properties of keyboard
Or, after I've loaded http://project.localhost
and then try to add something after the current URL:
- click in address bar, URL has been shortened to
project.localhost
- add
/test.html
to end - browser sends
project.localhost/test.html
to Duck Duck Go - user considers software violence
Solution 1:[1]
Turns out that the Safari extension might be a long term solution. At this moment, I can't manage the developer membership cost. But here's the working code, for Future Me and anyone else looking into this.
In the extension's global page <script>
:
(function() {
safari.application.addEventListener("beforeSearch", function(event) {
if (event.query.split("/")[0].split(".").pop() == "localhost") {
event.preventDefault();
safari.application.activeBrowserWindow.activeTab.url = "http://" + event.query;
}
}, true);
})();
Solution 2:[2]
If you just type the trailing '/', then the search will be bypassed.
Solution 3:[3]
I just found this question while looking for a solution to the same problem. Good news, there's an easy solution that I just stumbled upon after not finding an answer.
Open System Preferences Open Network Click Advanced button Click Proxies tab
Then in the "Bypass proxy settings for these Hosts & Domains:" add in localhost to the list. Here's what I did with mine. I'm using .home for my local domains in my PiHole. Now if I type "router.home" into Safari my router's config page loads up.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mark Priddy |
Solution 2 | ElectroBuddha |
Solution 3 | McCygnus |