diff --git a/lib/util/host-rules.ts b/lib/util/host-rules.ts
index c2e1225166dbff61f908c47c5c334639bb3b5c50..e9352c2dc0b586d97965b89599928d9da8b99003 100644
--- a/lib/util/host-rules.ts
+++ b/lib/util/host-rules.ts
@@ -60,10 +60,12 @@ function matchesHostType(rule: HostRule, search: HostRuleSearch) {
 }
 
 function matchesDomainName(rule: HostRule, search: HostRuleSearch) {
+  const hostname = search.url && URL.parse(search.url).hostname;
   return (
     search.url &&
     rule.domainName &&
-    URL.parse(search.url).hostname!.endsWith(rule.domainName)
+    hostname &&
+    hostname.endsWith(rule.domainName)
   );
 }