It can be difficult to understand some of your dog's more idiosyncratic behaviors, but when he's rubbing his head on the floor, it usually means one of only a few things. Sometimes it's because something is wrong with your dog, and he's rubbing his head on the floor as temporary means of relief. Other times, it's a relatively harmless habit. If you notice your dog rubbing his head frequently, monitor his behavior and consult your vet.
Dogs don't always rub their heads on things because something is wrong -- sometimes they just like doing it. If your dog is rubbing his head on the floor, it may be because he smells something there that he finds appealing and he wants to pick up the scent for himself. This is especially common when you get outside, where dogs may like to rub their heads and shoulders in the grass. Your dog could be rubbing his head this way because he wants to spread his own scent and mark his territory.
Infections and Allergies
When your dog has an infection, particularly an ear infection, one of the behaviors he may demonstrate is rubbing his head on the ground. It's because the infection irritates his ear, causing it to leak discharge as well as give the skin a red, swollen appearance. If his ears look OK, he may be rubbing his head because he's allergic to something. Allergies often manifest in itchiness, so if he recently switched to a new food or you introduced a new household product like laundry detergent, he may be suffering allergies that make his head itch.
Ear mites are parasites that nest inside your dog's ears. When they do, they prompt an intense irritating reaction. Your dog's ears become severely itchy and sensitive, and he will grind his ears into the floor or against furniture to try and ease the frustration. As an infestation becomes bigger, the irritation gets worse, and your dog will furiously scratch and grind at his ears to try and relieve the pain -- he needs to see a vet as soon as possible.
Dogs that have facial folds need to have them cleaned out regularly. Pugs and bulldogs, for example, have faces beset by deep wrinkles, and the insides of those wrinkles can become irritated. The wrinkles collect dirt, grime, bacteria and food particles, and your dog may rub his face against the floor to try and relieve the discomfort. Wipe his folds out on a regular basis to prevent this discomfort and the accompanying behavior.
Even dogs without facial folds may indulge in head and face rubbing as a way of cleaning off their faces. For example, if your dog wakes up with eye rheum -- colloquially known as "eye boogers" -- he may rub his head on the carpet to clear it off. Wiping off his face with a soft tissue when he wakes up or when his face gets dirty can help him avoid doing the work himself.