Sebastan12 Posted March 30, 2021 Share Posted March 30, 2021 (edited) Hey dear PrestaShop developer Comunity.. so i have been tearing my hair out over a minor thing that i just can't seem to find any valuable information on. Neiter in the dev.docs nor through google ( maby i do not know what I am searching for). ---------------------------------------------------------------------------------------- So my goal is to write a module that does redirects in Prestashop 1.7.7.1 I have URL 1 and I want the module to redirect to URL 2For example: myshop.com/specialBlogPage -> ( redirects to) -> myshop.com/blog/43-yes-verry-special myshop.com/amazingbracelet -> (redirects to) -> myshop.com/brachelets/23-saphires-and-ruby-bracelet I wanna make it modular in the backend ( manage redirects i made) ---------------------------------------------------------------------------------------- If someone could help me / point me to a usefull resource on how to do redirects in Prestashop 1.17.7.1 I would be forever thankfull ❤️ Edited March 30, 2021 by Sebastan12 Better clarification of the question (see edit history) Link to comment Share on other sites More sharing options...
Pedram Posted April 1, 2021 Share Posted April 1, 2021 (edited) Hmm, How are you creating these myshop.com/specialBlogPage urls ? if they are CMS pages, IIRC there should be some built-in feature in the Prestashop to redirect them to your custom URL. But instead, if you are creating them using your module controller, like the content of the page might change depend on the parameters value, For example controller is "Blog", and parameter is "Page" and value is "special" then it will open your special blog page. Then you can add routes using "moduleRoutes" in your module for them. First, Make a module or go to this link to generate a simple one : https://validator.prestashop.com/generator Second, Add this Hook to the install section : $this->registerHook('moduleRoutes') Third, Add this section to your module code in same file (YourModuleName.php) as the install section above : public function hookModuleRoutes($params){ $my_routes = array( 'YourRouteName1' => array( 'controller' => 'NameOfController1', 'rule' => 'blog/{id}-{name}/', 'keywords' => array( 'id' => array('regexp' => '[\w]+', 'param' => 'id'), 'name' => array('regexp' => '[\w]+', 'param' => 'name'), ), 'params' => array( 'fc' => 'module', 'module' => 'YourModuleName' ) ), 'YourRouteName2' => array( 'controller' => 'NameOfController2', 'rule' => 'branchelets/{id}-{name}', 'keywords' => array( 'id' => array('regexp' => '[\w]+', 'param' => 'id'), 'name' => array('regexp' => '[\w]+', 'param' => 'name'), ), 'params' => array( 'fc' => 'module', 'module' => 'YourModuleName' ) ) ); return $my_routes; } This will make it that instead of MyShop.com/Modules/YourModuleName/?Controller=NameOfController1&id=43&name=Yes-very-special (If friendly URL turned on) Your page will show up as myshop.com/blog/43-yes-verry-special Same goes for the 2nd URL. MyShop.com/Modules/YourModuleName/NameOfController2/id=23&name=saphires-and-ruby-bracelet --> myshop.com/brachelets/23-saphires-and-ruby-bracelet Edited April 1, 2021 by Pedram (see edit history) 1 Link to comment Share on other sites More sharing options...
Sebastan12 Posted April 24, 2021 Author Share Posted April 24, 2021 :3 thank you this helps me out a ton. Link to comment Share on other sites More sharing options...
Shapes Posted March 11, 2022 Share Posted March 11, 2022 Hello, Since update to 1.7.8.4 this does not seems to work anymore, any idea why please? Link to comment Share on other sites More sharing options...
Shapes Posted March 11, 2022 Share Posted March 11, 2022 Apparently a PrestaShop bug: https://github.com/PrestaShop/PrestaShop/issues/27854 that just got a fix: https://github.com/PrestaShop/PrestaShop/pull/27874/files Fix works fine on my side. Link to comment Share on other sites More sharing options...
Ain ul Haq Posted April 16 Share Posted April 16 You can use: 1- Url Redirect Module https://addons.prestashop.com/en/url-redirects/27738-pretty-urls-url-redirects-manager-pack-of-2.html 2- Pretty URL module that also cleans the URLs https://addons.prestashop.com/en/url-redirects/21856-url-redirect-manage-301-302-303-redirects-404-urls.html Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now