diff --git wp-includes/formatting.php wp-includes/formatting.php
index 85d4e7e..4ae9fcb 100644
--- wp-includes/formatting.php
+++ wp-includes/formatting.php
@@ -3782,8 +3782,16 @@ function esc_url( $url, $protocols = null, $_context = 'display' ) {
 	 * link starting with /, # or ? or a php file).
 	 */
 	if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) &&
-		! preg_match('/^[a-z0-9-]+?\.php/i', $url) )
-		$url = 'http://' . $url;
+		! preg_match('/^[a-z0-9-]+?\.php/i', $url) ) {
+			$scheme = 'http://';
+			if ( is_ssl() ) {
+				$response = wp_remote_get( 'https://' . $url );
+				if ( ! is_wp_error( $response ) && $response['response']['code'] === 200 ) {
+					$scheme = 'https://';
+				}
+			}
+			$url = $scheme . $url;
+		}
 
 	// Replace ampersands and single quotes only when displaying.
 	if ( 'display' == $_context ) {
