From 2f5fd6e899b355409fdf40692643dc25f2257f6c Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 31 May 2021 11:17:15 +0200 Subject: [PATCH 1/4] autoindex.php --- Config/config.xml | 6 +++ Config/routing.xml | 7 +++ Controller/Admin/ModuleConfigController.php | 24 +++++++++- EventListeners/RequestListener.php | 45 +++++++++++++++++++ I18n/backOffice/default/fr_FR.php | 2 + .../RewriteUrl/module-configuration-js.html | 21 +++++++++ .../RewriteUrl/module-configuration.html | 18 +++++++- 7 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 EventListeners/RequestListener.php diff --git a/Config/config.xml b/Config/config.xml index 0e2de2a..702bf0d 100755 --- a/Config/config.xml +++ b/Config/config.xml @@ -22,6 +22,12 @@ + + + + + + diff --git a/Config/routing.xml b/Config/routing.xml index 8db07fa..90aaebe 100755 --- a/Config/routing.xml +++ b/Config/routing.xml @@ -13,6 +13,13 @@ RewriteUrl\Controller\Admin\ModuleConfigController::setRewritingEnableAction + + + + RewriteUrl\Controller\Admin\ModuleConfigController::setRedirectionEnableAction + + + RewriteUrl\Controller\Admin\ModuleConfigController::addRuleAction diff --git a/Controller/Admin/ModuleConfigController.php b/Controller/Admin/ModuleConfigController.php index 4e9fe0a..3cd5504 100644 --- a/Controller/Admin/ModuleConfigController.php +++ b/Controller/Admin/ModuleConfigController.php @@ -23,11 +23,13 @@ public function viewConfigAction($params = array()) } $isRewritingEnabled = ConfigQuery::isRewritingEnable(); + $isRedirectionEnabled = ConfigQuery::isRedirectionEnable(); return $this->render( "RewriteUrl/module-configuration", [ - "isRewritingEnabled" => $isRewritingEnabled + "isRewritingEnabled" => $isRewritingEnabled, + "isRedirectionEnabled" => $isRedirectionEnabled, ] ); } @@ -136,6 +138,26 @@ public function setRewritingEnableAction() } } + // check redirection_enable status & write an entry if there is none // + + public function setRedirectionEnableAction() + { + $request = $this->getRequest()->request; + $isRedirectionEnable = $request->get("redirection_enable", null); + + if ($isRedirectionEnable !== null) { + ConfigQuery::write("redirection_enable", $isRedirectionEnable ? 1 : 0); + return $this->jsonResponse(json_encode(["state" => "Success"]), 200); + } else { + return $this->jsonResponse(Translator::getInstance()->trans( + "Unable to change the configuration variable.", + [], + RewriteUrl::MODULE_DOMAIN + ), 500); + } + } + // ############################## // + public function addRuleAction() { try { diff --git a/EventListeners/RequestListener.php b/EventListeners/RequestListener.php new file mode 100644 index 0000000..1698570 --- /dev/null +++ b/EventListeners/RequestListener.php @@ -0,0 +1,45 @@ +getRequest(); + $fullPath = $request->getUri(); + $regexToMatch = "^\/index.php^"; + + if (preg_match($regexToMatch, $fullPath)) + { + $newPath = preg_replace($regexToMatch, "", $fullPath) ; + $event->setResponse(new RedirectResponse( + $newPath, + 301 + )); + } + } + } + + // event to listen to + public static function getSubscribedEvents() + { + return + [ + KernelEvents::REQUEST => ["redirect"], + ]; + } + +} \ No newline at end of file diff --git a/I18n/backOffice/default/fr_FR.php b/I18n/backOffice/default/fr_FR.php index 6757470..0bbed44 100755 --- a/I18n/backOffice/default/fr_FR.php +++ b/I18n/backOffice/default/fr_FR.php @@ -29,6 +29,8 @@ 'Do you really want to delete the url %html ?' => 'Voulez-vous vraiment supprimer l\'url %html ?', 'Edit information in %lng' => 'Modifier l\'information en %lng', 'Enable URL rewriting' => 'Activer la réécriture d\'URL', + 'Enable index.php redirection' => 'Activer la redirection des URL contenant index.php', + 'URL which contain index.php will be erased' => 'Les url contenants "index.php" seront supprimées et redirigées automatiquement', 'Enter a URL with a leading \'/\' and no domain name. Ex : for \'www.mysite.com/one/two\', enter \'/one/two\'.' => 'Saisissez une URL commençant par un \'/\' et sans nom de domaine. Ex : pour \'www.monsite.com/un/deux\', saisissez \'/un/deux\'.', 'Enter new rule position' => 'Saisir une nouvelle position de règle', 'Error this url already exist you can reassign by follow this ' => 'Erreur cette url existe déjà, vous pouvez la réassigner en suivant ce ', diff --git a/templates/backOffice/default/RewriteUrl/module-configuration-js.html b/templates/backOffice/default/RewriteUrl/module-configuration-js.html index 12ec175..849e023 100644 --- a/templates/backOffice/default/RewriteUrl/module-configuration-js.html +++ b/templates/backOffice/default/RewriteUrl/module-configuration-js.html @@ -41,6 +41,27 @@ }); }); + // index.php redirection ajax request + $(".js_switch_redirection").on("switch-change", function (event, data) { + $loader.show(); + var checkbox = $(this); + + $.ajax({ + url : '{url path="/admin/module/RewriteUrl/config/setRedirectionEnable"}', + data : { redirection_enable : (data.value ? 1 : 0) }, + type : 'post', + success : function(){ + $loader.hide(); + location.reload() + }, + error : function(jqXHR, textStatus, errorThrown) { + $alertError.html(jqXHR.responseText); + checkbox.bootstrapSwitch('toggleState', true); + $loader.hide(); + } + }); + }); + // ################################## $('.js_editable_rule_position').editable({ diff --git a/templates/backOffice/default/RewriteUrl/module-configuration.html b/templates/backOffice/default/RewriteUrl/module-configuration.html index c55bb42..fe6418d 100644 --- a/templates/backOffice/default/RewriteUrl/module-configuration.html +++ b/templates/backOffice/default/RewriteUrl/module-configuration.html @@ -39,8 +39,22 @@ {intl l="Set the config variable 'rewriting_enable'"} - - + + +
+
+
+
+
+ +
+ +
+
+ {intl l="URL which contain index.php will be erased"} +
+
+
From 3330807f45ccfe2cc3ed890dbacfb25d8f5b0a5b Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 1 Jun 2021 16:42:21 +0200 Subject: [PATCH 2/4] adding feature to activate https redirection --- .zip | Bin 0 -> 172 bytes CHANGELOG.md | 0 Config/config.xml | 8 +- Config/routing.xml | 12 +- Config/schema.xml | 0 Config/sqldb.map | 0 Config/thelia.sql | 0 Config/update/1.4.8.sql | 0 Config/update/1.5.0.sql | 0 Controller/Admin/ModuleConfigController.php | 37 +++- .../Admin/NotRewritenUrlsAdminController.php | 0 EventListeners/KernelExceptionListener.php | 0 EventListeners/RequestListener.php | 18 +- Hook/ConfigurationHook.php | 0 I18n/backOffice/default/fr_FR.php | 6 +- I18n/fr_FR.php | 0 Loop/NotRewritenUrlCategoryLoop.php | 0 Loop/RewriteUrlRuleLoop.php | 0 Model/Base/RewriteurlRule.php | 0 Model/Base/RewriteurlRuleParam.php | 0 Model/Base/RewriteurlRuleParamQuery.php | 0 Model/Base/RewriteurlRuleQuery.php | 0 Model/Base/RewritingRedirectType.php | 0 Model/Base/RewritingRedirectTypeQuery.php | 0 Model/Map/RewriteurlRuleParamTableMap.php | 0 Model/Map/RewriteurlRuleTableMap.php | 0 Model/Map/RewritingRedirectTypeTableMap.php | 0 Model/RewriteurlRule.php | 0 Model/RewriteurlRuleParam.php | 0 Model/RewriteurlRuleParamQuery.php | 0 Model/RewriteurlRuleQuery.php | 0 Model/RewritingRedirectType.php | 0 Model/RewritingRedirectTypeQuery.php | 0 Model/RewritingUrlOverride.php | 0 Service/RewritingRouterFirst.php | 0 Service/RewritingRouterLast.php | 0 logo.jpg | Bin screenshot/screenshot-1.jpeg | Bin screenshot/screenshot-2.jpeg | Bin screenshot/screenshot-3.png | Bin .../RewriteUrl/module-configuration-js.html | 28 ++- .../RewriteUrl/module-configuration.html | 206 +++++++++--------- .../default/RewriteUrl/tab-value-render.html | 0 .../default/configuration-catalog.html | 0 .../default/list-notrewritenurls.html | 0 45 files changed, 198 insertions(+), 117 deletions(-) create mode 100644 .zip mode change 100644 => 100755 CHANGELOG.md mode change 100644 => 100755 Config/schema.xml mode change 100644 => 100755 Config/sqldb.map mode change 100644 => 100755 Config/thelia.sql mode change 100644 => 100755 Config/update/1.4.8.sql mode change 100644 => 100755 Config/update/1.5.0.sql mode change 100644 => 100755 Controller/Admin/ModuleConfigController.php mode change 100644 => 100755 Controller/Admin/NotRewritenUrlsAdminController.php mode change 100644 => 100755 EventListeners/KernelExceptionListener.php mode change 100644 => 100755 EventListeners/RequestListener.php mode change 100644 => 100755 Hook/ConfigurationHook.php mode change 100644 => 100755 I18n/fr_FR.php mode change 100644 => 100755 Loop/NotRewritenUrlCategoryLoop.php mode change 100644 => 100755 Loop/RewriteUrlRuleLoop.php mode change 100644 => 100755 Model/Base/RewriteurlRule.php mode change 100644 => 100755 Model/Base/RewriteurlRuleParam.php mode change 100644 => 100755 Model/Base/RewriteurlRuleParamQuery.php mode change 100644 => 100755 Model/Base/RewriteurlRuleQuery.php mode change 100644 => 100755 Model/Base/RewritingRedirectType.php mode change 100644 => 100755 Model/Base/RewritingRedirectTypeQuery.php mode change 100644 => 100755 Model/Map/RewriteurlRuleParamTableMap.php mode change 100644 => 100755 Model/Map/RewriteurlRuleTableMap.php mode change 100644 => 100755 Model/Map/RewritingRedirectTypeTableMap.php mode change 100644 => 100755 Model/RewriteurlRule.php mode change 100644 => 100755 Model/RewriteurlRuleParam.php mode change 100644 => 100755 Model/RewriteurlRuleParamQuery.php mode change 100644 => 100755 Model/RewriteurlRuleQuery.php mode change 100644 => 100755 Model/RewritingRedirectType.php mode change 100644 => 100755 Model/RewritingRedirectTypeQuery.php mode change 100644 => 100755 Model/RewritingUrlOverride.php mode change 100644 => 100755 Service/RewritingRouterFirst.php mode change 100644 => 100755 Service/RewritingRouterLast.php mode change 100644 => 100755 logo.jpg mode change 100644 => 100755 screenshot/screenshot-1.jpeg mode change 100644 => 100755 screenshot/screenshot-2.jpeg mode change 100644 => 100755 screenshot/screenshot-3.png mode change 100644 => 100755 templates/backOffice/default/RewriteUrl/module-configuration-js.html mode change 100644 => 100755 templates/backOffice/default/RewriteUrl/module-configuration.html mode change 100644 => 100755 templates/backOffice/default/RewriteUrl/tab-value-render.html mode change 100644 => 100755 templates/backOffice/default/configuration-catalog.html mode change 100644 => 100755 templates/backOffice/default/list-notrewritenurls.html diff --git a/.zip b/.zip new file mode 100644 index 0000000000000000000000000000000000000000..610122191316b23c936aa3f31a961ed69fe0ebef GIT binary patch literal 172 zcmWIWW@h1H00D>EgF#>hl;CENVF*esFUl-Q4K2#i4-MgDVAinQmT=EvTS93CHv=Qf w3uXoeFcIL*$Rx*%%NPl$fdUMF9YIVKLs=n)Vi?HE22#ohgn>ZX6~tix06oGSq5uE@ literal 0 HcmV?d00001 diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 diff --git a/Config/config.xml b/Config/config.xml index 702bf0d..96e35b1 100755 --- a/Config/config.xml +++ b/Config/config.xml @@ -23,7 +23,13 @@ - + + + + + + + diff --git a/Config/routing.xml b/Config/routing.xml index 90aaebe..fd9f731 100755 --- a/Config/routing.xml +++ b/Config/routing.xml @@ -14,9 +14,15 @@ RewriteUrl\Controller\Admin\ModuleConfigController::setRewritingEnableAction - - - RewriteUrl\Controller\Admin\ModuleConfigController::setRedirectionEnableAction + + + RewriteUrl\Controller\Admin\ModuleConfigController::setIndexRedirectionEnableAction + + + + + + RewriteUrl\Controller\Admin\ModuleConfigController::setHttpsRedirectionEnableAction diff --git a/Config/schema.xml b/Config/schema.xml old mode 100644 new mode 100755 diff --git a/Config/sqldb.map b/Config/sqldb.map old mode 100644 new mode 100755 diff --git a/Config/thelia.sql b/Config/thelia.sql old mode 100644 new mode 100755 diff --git a/Config/update/1.4.8.sql b/Config/update/1.4.8.sql old mode 100644 new mode 100755 diff --git a/Config/update/1.5.0.sql b/Config/update/1.5.0.sql old mode 100644 new mode 100755 diff --git a/Controller/Admin/ModuleConfigController.php b/Controller/Admin/ModuleConfigController.php old mode 100644 new mode 100755 index 3cd5504..111ec81 --- a/Controller/Admin/ModuleConfigController.php +++ b/Controller/Admin/ModuleConfigController.php @@ -23,13 +23,16 @@ public function viewConfigAction($params = array()) } $isRewritingEnabled = ConfigQuery::isRewritingEnable(); - $isRedirectionEnabled = ConfigQuery::isRedirectionEnable(); + $isIndexRedirectionEnabled = ConfigQuery::isIndexRedirectionEnable(); + $isHttpsRedirectionEnabled = ConfigQuery::isHttpsRedirectionEnable(); return $this->render( "RewriteUrl/module-configuration", [ "isRewritingEnabled" => $isRewritingEnabled, - "isRedirectionEnabled" => $isRedirectionEnabled, + "isIndexRedirectionEnabled" => $isIndexRedirectionEnabled, + "isHttpsRedirectionEnabled" => $isHttpsRedirectionEnabled, + ] ); } @@ -138,15 +141,35 @@ public function setRewritingEnableAction() } } - // check redirection_enable status & write an entry if there is none // + // check index_redirection_enable status & write an entry if there is none // - public function setRedirectionEnableAction() + public function setIndexRedirectionEnableAction() + { + $request = $this->getRequest()->request; + $isIndexRedirectionEnable = $request->get("index_redirection_enable", null); + + if ($isIndexRedirectionEnable !== null) { + ConfigQuery::write("index_redirection_enable", $isIndexRedirectionEnable ? 1 : 0); + return $this->jsonResponse(json_encode(["state" => "Success"]), 200); + } else { + return $this->jsonResponse(Translator::getInstance()->trans( + "Unable to change the configuration variable.", + [], + RewriteUrl::MODULE_DOMAIN + ), 500); + } + } + // ############################## // + + // check https_redirection_enable status & write an entry if there is none // + + public function setHttpsRedirectionEnableAction() { $request = $this->getRequest()->request; - $isRedirectionEnable = $request->get("redirection_enable", null); + $isHttpsRedirectionEnable = $request->get("https_redirection_enable", null); - if ($isRedirectionEnable !== null) { - ConfigQuery::write("redirection_enable", $isRedirectionEnable ? 1 : 0); + if ($isHttpsRedirectionEnable !== null) { + ConfigQuery::write("https_redirection_enable", $isHttpsRedirectionEnable ? 1 : 0); return $this->jsonResponse(json_encode(["state" => "Success"]), 200); } else { return $this->jsonResponse(Translator::getInstance()->trans( diff --git a/Controller/Admin/NotRewritenUrlsAdminController.php b/Controller/Admin/NotRewritenUrlsAdminController.php old mode 100644 new mode 100755 diff --git a/EventListeners/KernelExceptionListener.php b/EventListeners/KernelExceptionListener.php old mode 100644 new mode 100755 diff --git a/EventListeners/RequestListener.php b/EventListeners/RequestListener.php old mode 100644 new mode 100755 index 1698570..d1c8440 --- a/EventListeners/RequestListener.php +++ b/EventListeners/RequestListener.php @@ -16,7 +16,7 @@ class RequestListener implements EventSubscriberInterface public function redirect(GetResponseEvent $event) { - if (ConfigQuery::isRedirectionEnable()) + if (ConfigQuery::isIndexRedirectionEnable()) { $request = $event->getRequest(); $fullPath = $request->getUri(); @@ -31,6 +31,21 @@ public function redirect(GetResponseEvent $event) )); } } + + if (ConfigQuery::isHttpsRedirectionEnable()) + { + $request = $event->getRequest(); + $fullPath = $request->getUri(); + + if (!$request->isSecure()) + { + $securePath = str_replace('http', 'https', $fullPath) ; + $event->setResponse(new RedirectResponse( + $securePath, + 301 + )); + } + } } // event to listen to @@ -41,5 +56,4 @@ public static function getSubscribedEvents() KernelEvents::REQUEST => ["redirect"], ]; } - } \ No newline at end of file diff --git a/Hook/ConfigurationHook.php b/Hook/ConfigurationHook.php old mode 100644 new mode 100755 diff --git a/I18n/backOffice/default/fr_FR.php b/I18n/backOffice/default/fr_FR.php index 0bbed44..ef2c22d 100755 --- a/I18n/backOffice/default/fr_FR.php +++ b/I18n/backOffice/default/fr_FR.php @@ -29,8 +29,10 @@ 'Do you really want to delete the url %html ?' => 'Voulez-vous vraiment supprimer l\'url %html ?', 'Edit information in %lng' => 'Modifier l\'information en %lng', 'Enable URL rewriting' => 'Activer la réécriture d\'URL', - 'Enable index.php redirection' => 'Activer la redirection des URL contenant index.php', - 'URL which contain index.php will be erased' => 'Les url contenants "index.php" seront supprimées et redirigées automatiquement', + 'Enable index.php redirection' => 'Activer la redirection d\'index.php', + 'Enable https redirection' => 'Activer la redirection HTTPS', + 'Auto redirect http to https protocol' => 'Rediriger automatiquement vers les adresses HTTPS', + 'URL which contain index.php will be erased' => 'Les url contenants "index.php" seront redirigées', 'Enter a URL with a leading \'/\' and no domain name. Ex : for \'www.mysite.com/one/two\', enter \'/one/two\'.' => 'Saisissez une URL commençant par un \'/\' et sans nom de domaine. Ex : pour \'www.monsite.com/un/deux\', saisissez \'/un/deux\'.', 'Enter new rule position' => 'Saisir une nouvelle position de règle', 'Error this url already exist you can reassign by follow this ' => 'Erreur cette url existe déjà, vous pouvez la réassigner en suivant ce ', diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php old mode 100644 new mode 100755 diff --git a/Loop/NotRewritenUrlCategoryLoop.php b/Loop/NotRewritenUrlCategoryLoop.php old mode 100644 new mode 100755 diff --git a/Loop/RewriteUrlRuleLoop.php b/Loop/RewriteUrlRuleLoop.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewriteurlRule.php b/Model/Base/RewriteurlRule.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewriteurlRuleParam.php b/Model/Base/RewriteurlRuleParam.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewriteurlRuleParamQuery.php b/Model/Base/RewriteurlRuleParamQuery.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewriteurlRuleQuery.php b/Model/Base/RewriteurlRuleQuery.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewritingRedirectType.php b/Model/Base/RewritingRedirectType.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewritingRedirectTypeQuery.php b/Model/Base/RewritingRedirectTypeQuery.php old mode 100644 new mode 100755 diff --git a/Model/Map/RewriteurlRuleParamTableMap.php b/Model/Map/RewriteurlRuleParamTableMap.php old mode 100644 new mode 100755 diff --git a/Model/Map/RewriteurlRuleTableMap.php b/Model/Map/RewriteurlRuleTableMap.php old mode 100644 new mode 100755 diff --git a/Model/Map/RewritingRedirectTypeTableMap.php b/Model/Map/RewritingRedirectTypeTableMap.php old mode 100644 new mode 100755 diff --git a/Model/RewriteurlRule.php b/Model/RewriteurlRule.php old mode 100644 new mode 100755 diff --git a/Model/RewriteurlRuleParam.php b/Model/RewriteurlRuleParam.php old mode 100644 new mode 100755 diff --git a/Model/RewriteurlRuleParamQuery.php b/Model/RewriteurlRuleParamQuery.php old mode 100644 new mode 100755 diff --git a/Model/RewriteurlRuleQuery.php b/Model/RewriteurlRuleQuery.php old mode 100644 new mode 100755 diff --git a/Model/RewritingRedirectType.php b/Model/RewritingRedirectType.php old mode 100644 new mode 100755 diff --git a/Model/RewritingRedirectTypeQuery.php b/Model/RewritingRedirectTypeQuery.php old mode 100644 new mode 100755 diff --git a/Model/RewritingUrlOverride.php b/Model/RewritingUrlOverride.php old mode 100644 new mode 100755 diff --git a/Service/RewritingRouterFirst.php b/Service/RewritingRouterFirst.php old mode 100644 new mode 100755 diff --git a/Service/RewritingRouterLast.php b/Service/RewritingRouterLast.php old mode 100644 new mode 100755 diff --git a/logo.jpg b/logo.jpg old mode 100644 new mode 100755 diff --git a/screenshot/screenshot-1.jpeg b/screenshot/screenshot-1.jpeg old mode 100644 new mode 100755 diff --git a/screenshot/screenshot-2.jpeg b/screenshot/screenshot-2.jpeg old mode 100644 new mode 100755 diff --git a/screenshot/screenshot-3.png b/screenshot/screenshot-3.png old mode 100644 new mode 100755 diff --git a/templates/backOffice/default/RewriteUrl/module-configuration-js.html b/templates/backOffice/default/RewriteUrl/module-configuration-js.html old mode 100644 new mode 100755 index 849e023..3feea89 --- a/templates/backOffice/default/RewriteUrl/module-configuration-js.html +++ b/templates/backOffice/default/RewriteUrl/module-configuration-js.html @@ -42,13 +42,35 @@ }); // index.php redirection ajax request - $(".js_switch_redirection").on("switch-change", function (event, data) { + $(".js_switch_index_redirection").on("switch-change", function (event, data) { $loader.show(); var checkbox = $(this); $.ajax({ - url : '{url path="/admin/module/RewriteUrl/config/setRedirectionEnable"}', - data : { redirection_enable : (data.value ? 1 : 0) }, + url : '{url path="/admin/module/RewriteUrl/config/setIndexRedirectionEnable"}', + data : { index_redirection_enable : (data.value ? 1 : 0) }, + type : 'post', + success : function(){ + $loader.hide(); + location.reload() + }, + error : function(jqXHR, textStatus, errorThrown) { + $alertError.html(jqXHR.responseText); + checkbox.bootstrapSwitch('toggleState', true); + $loader.hide(); + } + }); + }); + // ################################## + + // https redirection ajax request + $(".js_switch_https_redirection").on("switch-change", function (event, data) { + $loader.show(); + var checkbox = $(this); + + $.ajax({ + url : '{url path="/admin/module/RewriteUrl/config/setHttpsRedirectionEnable"}', + data : { https_redirection_enable : (data.value ? 1 : 0) }, type : 'post', success : function(){ $loader.hide(); diff --git a/templates/backOffice/default/RewriteUrl/module-configuration.html b/templates/backOffice/default/RewriteUrl/module-configuration.html old mode 100644 new mode 100755 index fe6418d..fdf39f5 --- a/templates/backOffice/default/RewriteUrl/module-configuration.html +++ b/templates/backOffice/default/RewriteUrl/module-configuration.html @@ -25,120 +25,128 @@ {hook name="module.configuration" location="module_configuration" modulecode="$module_code"} -
-
-
-
-
-
- -
- -
-
- {intl l="Set the config variable 'rewriting_enable'"} + +
+
+
+
+ +
+
- + {intl l="Set the config variable 'rewriting_enable'"} +
+
+ -
-
-
-
-
- -
- -
-
- {intl l="URL which contain index.php will be erased"} +
+
+
+ +
+ +
+
+ {intl l="URL which contain index.php will be erased"} +
+
+ + + +
+
+
+ +
+
+ {intl l="Auto redirect http to https protocol"} +
+
-
-
-
- {intl l="Rule management"} -
+
+
+
+ {intl l="Rule management"}
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- / - - / -
- -
- -
-
- - - - - - -

{intl l="Currently enabled rules"}


- - - - - - - - - - - - -
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ / + + / +
+ +
+ +
+
+ + + + + + +

{intl l="Currently enabled rules"}


+ + + + + + + + + + + + +
+
-
- - + {* index.php redirection switch *}
@@ -51,9 +51,9 @@ {intl l="URL which contain index.php will be erased"}
- + {*end of index.php redirection switch *} - + {* https redirection switch *}
@@ -65,7 +65,7 @@ {intl l="Auto redirect http to https protocol"}
- + {*end of https redirection switch *}
From 14ae2059fce65c2c2a42420aa37b19f610fc817a Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 2 Jun 2021 17:17:34 +0200 Subject: [PATCH 4/4] reorganized rewriting & redirection methods --- Controller/Admin/ModuleConfigController.php | 33 +++++++++---------- .../RewriteUrl/module-configuration.html | 4 +-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Controller/Admin/ModuleConfigController.php b/Controller/Admin/ModuleConfigController.php index 39f5d68..d7e371d 100755 --- a/Controller/Admin/ModuleConfigController.php +++ b/Controller/Admin/ModuleConfigController.php @@ -130,16 +130,13 @@ public function setRewritingEnableAction() $request = $this->getRequest()->request; $isRewritingEnable = $request->get("rewriting_enable", null); - if ($isRewritingEnable !== null) { - ConfigQuery::write("rewriting_enable", $isRewritingEnable ? 1 : 0); - return $this->jsonResponse(json_encode(["state" => "Success"]), 200); - } else { - return $this->jsonResponse(Translator::getInstance()->trans( - "Unable to change the configuration variable.", - [], - RewriteUrl::MODULE_DOMAIN - ), 500); + if ($isRewritingEnable === null) { + + throw new BadRequestHttpException('Unable to change the configuration variable.'); } + ConfigQuery::write("rewriting_enable", $isRewritingEnable ? 1 : 0); + return $this->jsonResponse(json_encode(["state" => "Success"]), 200); + } public function setIndexRedirectionEnableAction() @@ -147,12 +144,13 @@ public function setIndexRedirectionEnableAction() $request = $this->getRequest()->request; $isIndexRedirectionEnable = $request->get("index_redirection_enable", null); - if ($isIndexRedirectionEnable !== null) { - RewriteUrl::setConfigValue("index_redirection_enable", $isIndexRedirectionEnable); - return $this->jsonResponse(json_encode(["state" => "Success"]), 200); - } else { + if ($isIndexRedirectionEnable === null) { + throw new BadRequestHttpException('Missing index_redirection_enable parameter in url'); } + RewriteUrl::setConfigValue("index_redirection_enable", $isIndexRedirectionEnable); + return $this->jsonResponse(json_encode(["state" => "Success"]), 200); + } public function setHttpsRedirectionEnableAction() @@ -160,12 +158,13 @@ public function setHttpsRedirectionEnableAction() $request = $this->getRequest()->request; $isHttpsRedirectionEnable = $request->get("https_redirection_enable", null); - if ($isHttpsRedirectionEnable !== null) { - RewriteUrl::setConfigValue("https_redirection_enable", $isHttpsRedirectionEnable); - return $this->jsonResponse(json_encode(["state" => "Success"]), 200); - } else { + if ($isHttpsRedirectionEnable === null) { + throw new BadRequestHttpException('Missing https_redirection_enable parameter in url'); } + RewriteUrl::setConfigValue("https_redirection_enable", $isHttpsRedirectionEnable); + return $this->jsonResponse(json_encode(["state" => "Success"]), 200); + } public function addRuleAction() diff --git a/templates/backOffice/default/RewriteUrl/module-configuration.html b/templates/backOffice/default/RewriteUrl/module-configuration.html index 0a3119d..45f5bb5 100755 --- a/templates/backOffice/default/RewriteUrl/module-configuration.html +++ b/templates/backOffice/default/RewriteUrl/module-configuration.html @@ -51,7 +51,7 @@ {intl l="URL which contain index.php will be erased"}
- {*end of index.php redirection switch *} + {* end of index.php redirection switch *} {* https redirection switch *}
@@ -65,7 +65,7 @@ {intl l="Auto redirect http to https protocol"}
- {*end of https redirection switch *} + {* end of https redirection switch *}