Possible to remove taxonomy from permalink if uncategorized?


I’m working on a client’s website who requested that the custom search functionality I’m building out provide a number of ‘pretty’ permalinks that they can use for ad campaigns.

The post types I’m working with are community, floorplan, and ready-made homes, and they want to be able to have direct links to search results by county and community.

To achieve this, I set up taxonomies that would create nicely formatted URLS such as {county}/{community}, {county}/{community}/{floorplan} {county}/{community}/{ready-made}.

This is all working fine, however it leads to some issues. For example, If you do not specify a county in your search, you will get links like uncategorized/{community} returned in the results.

Is there any way that you can remove uncategorized taxonomy from the URL, but leave the taxonomy in if it exists?

I’ve figured out how to update the URLs in the search results, however they will lead to 404s if left completely empty because they technically don’t exist if you remove the taxonomy from the url. Ideally, I would want them to just redirect to communities/{community} for example, instead of communities/uncategorized/{community}