diff --git a/lib/Uris.hs b/lib/Uris.hs
index 3aad1da711103ee85b4f206b2e076ccf648e638e..598aa46cd22dce4e17746d6837385c0728acdeb2 100644
--- a/lib/Uris.hs
+++ b/lib/Uris.hs
@@ -24,7 +24,7 @@ import           GHC.Generics            (Generic)
 import           GHC.TypeLits            (KnownSymbol, symbolVal)
 import           Text.Regex.TDFA         ((=~))
 import Witherable (mapMaybe)
-
+import Network.URI.Encode as URI
 
 data Substitution =
     Prefixed { prefix :: Text, blocked :: [Text], allowed :: [Text], scope :: [String] }
@@ -98,7 +98,7 @@ applySubsts s substs uri =  do
         Prefixed {..}
           | domain `elem` blocked -> Left IsBlocked
           | domain `elem` allowed -> Right uri
-          | otherwise -> Right (prefix <> domain <> rest)
+          | otherwise -> Right (prefix <> URI.encodeText uri)
         Allowed _ domains -> if domain `elem` domains
           then Right uri
           else Left (DomainIsBlocked domains)
diff --git a/walint.cabal b/walint.cabal
index 4f03b256228140205eb0b2c0f044c2a0dd9dfcd1..100a3d0bbe46316d12d7179616281e9361851188 100644
--- a/walint.cabal
+++ b/walint.cabal
@@ -56,7 +56,8 @@ library
                       extra,
                       witherable,
                       dotgen,
-                      text-metrics
+                      text-metrics,
+                      uri-encode
 
 -- TODO: move more stuff into lib, these dependencies are silly
 executable walint