How to prevent Firefox converting 'localhost/*' URLs into search queries?

24

6

Since upgrading from Firefox 3.6.x, my address bar has a quirk that never used to be there. When I type in, for example:

localhost/my_dir/index.php

Firefox turns it into a search query, my search engine is Google. To work around this (after forgetting I need to do this almost every time for FF), I must type in:

http://localhost/my_dir/index.php

This way, I am directed correctly to my localhost server. I don't need to do this for any other browser, and I thought this Q/A on URL trimming might change the behaviour, but it didn't.

Any ideas on how I can prevent 'localhost' from being turned into a search query?

danjah

Posted 2012-01-27T02:36:18.033

Reputation: 395

This should not happen anymore as browser.fixup.domainwhitelist.localhost with true is introduced in recent versions of Firefox. – koppor – 2019-09-21T08:45:24.170

Answers

23

  1. Type about:config in the URL bar
  2. In the filter search box, type browser.fixup.alternate.suffix
  3. Double click this entry to edit it and remove: .com

Now your localhost files should work without having to add http://.

tao

Posted 2012-01-27T02:36:18.033

Reputation: 1 355

2This doesnt work for me! I've restarted Firefox and entering "localhost:4567" does a google search! – IanVaughan – 2012-02-21T11:35:02.997

14I do not think this is the correct answer to this question, as it rather prevents FF appending .com to anything you type into the address bar. However, this works fine. For the sake of completeness: I found this setting better to use: browser.fixup.alternate.enabled, as above solution still prepended .www (there's a separete setting for this (called browser.fixup.alternate.prefix). – peterp – 2013-01-22T10:03:34.013

2

@IanVaughan With regard to the question, I consider this to be the correct answer, since it actually is about search queries: http://superuser.com/questions/382905/how-to-prevent-firefox-converting-localhost-urls-into-search-queries#answer-506884

– peterp – 2013-01-22T10:04:36.433

7

  1. In the Location bar, type about:config and press Enter.

  2. The about:config "This might void your warranty!" warning page may appear. Click I'll be careful, I promise!, to continue to the about:config page.

  3. In the Search field, type keyword.enabled.Double-click the keyword.enabled preference to set its value to false.

Please note that this will also prevent things that aren't URL-like from being used as search terms. For example, after making this change, if you type "how to tell if an egg is boiled" in the search bar, you'll just get a DNS error.

Other answers on this page give a way to attempt your suffix-less server name without modification (let's say you have a server in your domain called git, when you type just git/ and there is a DNS problem, instead of navigating to www.git.com you'll just get a DNS error page).

solution from Mozilla

i_Focus

Posted 2012-01-27T02:36:18.033

Reputation: 71

4

I know this is kind of a weird solution, but you could map localhost.com to 127.0.0.1 with your %windir%\system32\drivers\etc\hosts file.

Start notepad as administrator (by using the context menu on-top of it in the Start menu) and open the file %windir%\system32\drivers\etc\hosts, then add an entry like this:

127.0.0.1 localhost.com

to the end of the file. Save. Now you should be able to use localhost.com in place of localhost, which Firefox shouldn't complain about. Note that this works for practically any domain name you want, so you can make it shorter.

John Chadwick

Posted 2012-01-27T02:36:18.033

Reputation: 562

I've been using this method since I discovered it a couple of weeks ago. I use local.host. This is a much simpler solution than configuring the search engines in the browser. :) – iglvzx – 2012-01-27T03:00:49.350

Hmm... my hosts file already has "127.0.0.1 localhost" in it, I added the new entry, saved as admin - checked, restarted Firefox... same behaviour. @iglvzx: Do you literally type in "local.host/xyz" to the address bar after adding that to hosts? – danjah – 2012-01-27T03:28:50.763

@Danjah Yes, that's what I do. What did you add to your host file? – iglvzx – 2012-01-27T03:33:13.483

I added another line, under "127.0.0.1 localhost", "127.0.0.1 localhost.com", is that correct? – danjah – 2012-01-27T04:49:22.193

Ahhh, I see now, yeah, when I write "localhost.com/my_dir/index.php" it works "as expected". Very lame; its a few less characters to type, but still another thing to remember for another browser, until it changes again :P – danjah – 2012-01-27T04:51:15.280

1This will work in all of your browsers, and additionally you can make it shorter (e.g. l.h should work even.) – John Chadwick – 2012-01-27T05:24:39.260

@JohnChadwick That is correct. You can even shorten it to two characters. l. will work, too. :P – iglvzx – 2012-01-27T07:27:10.237

3

After trying the solutions already posted the problem was still occurring in my environment. A Google search directed to https://cdivilly.wordpress.com/2013/08/15/disable-firefox-redirecting-to-localhost-com/

This blog post suggested changing the browser.fixup.alternate.enabled property to false. This did the trick for me.

axiopisty

Posted 2012-01-27T02:36:18.033

Reputation: 196

1This solved it for me as well. Thanks, @axiopisty! – Asbjørn Ulsberg – 2016-05-09T19:41:00.987

2

To avoid this problem, I configured Firefox to always show the http:// protocol in URL bar.

In about:config, set browser.urlbar.trimURLs to false (https://support.mozilla.org/en-US/questions/881261).

baptx

Posted 2012-01-27T02:36:18.033

Reputation: 121

1

As said here:

  1. Type about:config in the URL bar,
  2. Create boolean parameter browser.fixup.domainwhitelist.domain_name (replace domain_name with your local domain name, like localhost),
  3. Set new parameter's value to true.

arcadius

Posted 2012-01-27T02:36:18.033

Reputation: 131

In recent versions of Firefox, the key browser.fixup.domainwhitelist.localhost is already there and set to true. – koppor – 2019-09-21T09:17:32.320

1

If you still want to be able to search from the address bar, but you also want to be able to open local URLs, you can set the about:config property browser.fixup.dns_first_for_single_words to true, which will do a DNS query for single words like localhost or myserver and only turn it into a search if the DNS query fails.

This gives you the best of both worlds - you can still search from the address bar, but if you put in the name of a machine on your LAN, then you'll just connect to that instead (assuming your DNS or hosts file is set up correctly of course!)

Malvineous

Posted 2012-01-27T02:36:18.033

Reputation: 1 881