diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index f7b24112ce..4f26a6b972 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -1178,15 +1178,18 @@ addressmap_have_mapping(const char *address, int update_expiry)
* new_address should be a newly dup'ed string, which we'll use or
* free as appropriate. We will leave address alone.
*
- * If new_address is NULL, or equal to address, remove
- * any mappings that exist from address.
- *
* If wildcard_addr is true, then the mapping will match any address
* equal to address, or any address ending with a period followed by
* address. If wildcard_addr and wildcard_new_addr are
* both true, the mapping will rewrite addresses that end with
* ".address" into ones that end with ".new_address."
*
+ * If new_address is NULL, or new_address is equal to
+ * address and wildcard_addr is equal to
+ * wildcard_new_addr, remove any mappings that exist from
+ * address.
+ *
+ *
* It is an error to set wildcard_new_addr if wildcard_addr is
* not set. */
void
@@ -1201,7 +1204,8 @@ addressmap_register(const char *address, char *new_address, time_t expires,
tor_assert(wildcard_addr);
ent = strmap_get(addressmap, address);
- if (!new_address || !strcasecmp(address,new_address)) {
+ if (!new_address || (!strcasecmp(address,new_address) &&
+ wildcard_addr == wildcard_new_addr)) {
/* Remove the mapping, if any. */
tor_free(new_address);
if (ent) {