diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index ae6fc1b..f9d9941 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -66,14 +66,14 @@ if( isset( $_SERVER['SERVER_NAME'] ) ) {
 	$serverName = 'localhost';
 }
 
-$wgProto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
+$wgProto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http';
 
 $wgServer = $wgProto.'://' . $serverName;
 # If the port is a non-standard one, add it to the URL
 if(    isset( $_SERVER['SERVER_PORT'] )
 	&& !strpos( $serverName, ':' )
 	&& (    ( $wgProto == 'http' && $_SERVER['SERVER_PORT'] != 80 )
-	 || ( $wgProto == 'https' && $_SERVER['SERVER_PORT'] != 443 ) ) ) {
+	 || ( $wgProto == 'https' && $_SERVER['SERVER_PORT'] != 443 && $_SERVER['SERVER_PORT'] != 80 ) ) ) {
 
 	$wgServer .= ":" . $_SERVER['SERVER_PORT'];
 }
