From 457712cd350082bfab755e12f19174578e15e107 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 11 Jan 2019 15:23:18 +0100 Subject: [PATCH] Fix HTTPS issue --- builder | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/builder b/builder index 2b5eeeaa..1ec7d50f 100755 --- a/builder +++ b/builder @@ -234,7 +234,7 @@ rcopy($path_debug_assets."templates/", $path_release_assets."templates/"); //Copy dark theme rcopy($path_debug_assets."css/dark_theme.css", $path_release_assets."css/dark_theme.css"); -//Create main HTML file +//Begin to write root PHP File notice("Generate PHP root file"); $page_src = ''; -$page_src .= load_page($release_conf); -file_put_contents(OUTPUT_DIRECTORY."index.php", $page_src); +}'; -// Add .htaccess file +// Begin .htaccess file $htaccess = ' RewriteEngine On RewriteRule ^index\.php$ - [L] @@ -271,11 +269,21 @@ if(defined(get_class($release)."::FORCE_HTTPS")){ $htaccess .= "\n\nRewriteCond %{HTTPS} !on\n"; $htaccess .= "RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}"; + //Add rules in root PHP file + $page_src .= "\n//Force HTTPS connection\n"; + $page_src .= "if(!isset(\$_SERVER[\"HTTPS\"]) || \$_SERVER[\"HTTPS\"] != \"on\")\n"; + $page_src .= "\theader('Location: https://'.\$_SERVER['HTTP_HOST'].\$_SERVER['REQUEST_URI']);\n"; } } + +//Write .htaccess file file_put_contents(OUTPUT_DIRECTORY.".htaccess", $htaccess); +//Write root index file +$page_src .= ' ?>'; +$page_src .= load_page($release_conf); +file_put_contents(OUTPUT_DIRECTORY."index.php", $page_src); //Done notice("Done.", TRUE);