diff --git a/.gitmodules b/.gitmodules
index fa2876d3b43ff8c9acd07c266baa99a2e61aa2ff..c43a3153a82c519f0ef9e0a0f0095332994c33cf 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
 [submodule "lua-matrix"]
 	path = lua-matrix
 	url = https://github.com/diggers-mt/lua-matrix
+[submodule "neturl"]
+	path = neturl
+	url = https://github.com/golgote/neturl.git
diff --git a/README.md b/README.md
index f2ce69db5ea096b2675b5e3a8a7c631c1e7f4ca4..4d519d07547d61966faa4a99a504fee39dd1b98b 100644
--- a/README.md
+++ b/README.md
@@ -62,12 +62,13 @@ secure.trusted_mods = matrix
 
 * `matrix.password`: Password for Matrix user
 
-* `matrix.server`: Server to connect to, include http(s), `https://matrix.org`
-
-* `matrix.port`: Server port, default `8448`
+* `matrix.server`: Server to connect to, include http(s) and port, `https://matrix.org`
 
 * `matrix.room_id`: Room to join, `room_id` in matrix. Always starts with `!`
 
+### Removed, don't use
+* `matrix.port`: Server port, default `8448`
+
 
 ## License
 
diff --git a/config.lua b/config.lua
index 82d6bf412d0766dba6fd002d5db9ff86aedb7d3e..6af12c3235226d3d232af6eb2da03111774c2213 100644
--- a/config.lua
+++ b/config.lua
@@ -28,6 +28,5 @@ end
 
 setting("string", "user", nil, true)      -- User name, fe @digbot:matrix.org
 setting("string", "server", nil, true)    -- Server address to connect to
-setting("number", "port", 8448)           -- Server port to connect to
 setting("string", "room_id", nil, true)   -- Channel to join (not needed?)
 setting("string", "password", nil, true)  -- Server password
diff --git a/debug.lua b/debug.lua
new file mode 100644
index 0000000000000000000000000000000000000000..ae66e81f5d6dee562945004bd7151fa7ef67811c
--- /dev/null
+++ b/debug.lua
@@ -0,0 +1,42 @@
+function eprintf(fmt, ...)
+  minetest.log("info", fmt:format(...))
+end
+
+
+function table_print (tt, indent, done)
+  done = done or {}
+  indent = indent or 0
+  if type(tt) == "table" then
+    local sb = {}
+    for key, value in pairs (tt) do
+      table.insert(sb, string.rep (" ", indent)) -- indent it
+      if type (value) == "table" and not done [value] then
+        done [value] = true
+        table.insert(sb, "{\n");
+        table.insert(sb, table_print (value, indent + 2, done))
+        table.insert(sb, string.rep (" ", indent)) -- indent it
+        table.insert(sb, "}\n");
+      elseif "number" == type(key) then
+        table.insert(sb, string.format("\"%s\"\n", tostring(value)))
+      else
+        table.insert(sb, string.format(
+            "%s = \"%s\"\n", tostring (key), tostring(value)))
+       end
+    end
+    return table.concat(sb)
+  else
+    return tt .. "\n"
+  end
+end
+
+function to_string( tbl )
+    if  "nil"       == type( tbl ) then
+        return tostring(nil)
+    elseif  "table" == type( tbl ) then
+        return table_print(tbl)
+    elseif  "string" == type( tbl ) then
+        return tbl
+    else
+        return tostring(tbl)
+    end
+end
diff --git a/init.lua b/init.lua
index 64c6fabef4b0da8e298a4a46f9fea40001968e52..55a01776449609db85398ab3789eb753cfaa8fd1 100644
--- a/init.lua
+++ b/init.lua
@@ -13,6 +13,7 @@ end
 
 ie.package.path =
     modpath.."/lua-matrix/?.lua;"
+    ..modpath.."/neturl/lib/?.lua;"
     ..ie.package.path
 
 matrix = {
@@ -24,16 +25,16 @@ matrix = {
 }
 
 dofile(modpath.."/config.lua")
-
-local function eprintf(fmt, ...)
-  minetest.log("info", fmt:format(...))
-end
+--dofile(modpath.."/debug.lua")
 
 -- Temporarily set require so that LuaIRC can access it
 local old_require = require
 require = ie.require
 
-local client = require("matrix").client(matrix.config.server..":"..matrix.config.port)
+dofile(modpath.."/validate_server.lua")
+
+local hs_url = validate_server(matrix.config.server)
+local client = require("matrix").client(hs_url)
 
 local start_ts = os.time() * 1000
 
diff --git a/neturl b/neturl
new file mode 160000
index 0000000000000000000000000000000000000000..e69ad0d005d7d70ff445d823ff69f1b41b6157ea
--- /dev/null
+++ b/neturl
@@ -0,0 +1 @@
+Subproject commit e69ad0d005d7d70ff445d823ff69f1b41b6157ea
diff --git a/settingtypes.txt b/settingtypes.txt
index d29f4e7842e385eb352c18bd6ce2cb858555df83..2bfbaa55d0bb8808675a87a9d29f9350ee74f485 100644
--- a/settingtypes.txt
+++ b/settingtypes.txt
@@ -7,10 +7,6 @@ matrix.user (Username) string
 # Server to connect to, include http(s)
 matrix.server (Matrix server) string https://matrix.org
 
-# Server port.
-# The standard matrix port is 8448
-matrix.port (Server port) int 8448
-
 # Channel the bot joins after connecting.
 matrix.room_id (Channel to join) string
 
diff --git a/validate_server.lua b/validate_server.lua
new file mode 100644
index 0000000000000000000000000000000000000000..2f7a28199b6ac9c1a7016bd5a4f649f5fcb5dea3
--- /dev/null
+++ b/validate_server.lua
@@ -0,0 +1,21 @@
+local url = require "net.url"
+
+function validate_server(hs_url)
+  u = url.parse(hs_url):normalize()
+
+  if not (u.host and u.scheme) then
+    return error("'"..hs_url.."' doesn't look like a valid url. Please specify scheme (http/s) and hostname")
+  end
+
+  if u.port and u.port == 8448 and u.scheme == 'http' then
+    return error("Port 8448 is for https, make sure your homeserver URL is correct")
+  end
+
+  if u.port and u.port == 8008 and u.scheme == 'https' then
+    minetest.log("warn", "Port 8008 is not https, make sure your homeserver URL is correct")
+  end
+
+  return hs_url
+end
+
+