Rewrite URL using GET params












0















I have a URL that looks like this:




site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729&sid=T80yDaUX1a




I'm trying to get it to look like this:




site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




I found this post on StackOverflow and tried to implement with amendments I though would work, but the page 500s now.



DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^*.html/(.*)$ /*.html?url=$1 [L,QSA]


This code was added to the pub/.htaccess file.



How do I go about getting the find param into a readable url?










share|improve this question

















This question has an open bounty worth +100
reputation from treyBake ending in 6 days.


This question has not received enough attention.

















  • Did you make all needed setup related to seo url in admin panel?

    – Kirill Korushkin
    21 hours ago











  • @KirillKorushkin not sure I understand - could you please try to clarify? :)

    – treyBake
    21 hours ago











  • are you suing nginx or apache?

    – Philipp Sander
    21 hours ago











  • @PhilippSander Apache :)

    – treyBake
    21 hours ago
















0















I have a URL that looks like this:




site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729&sid=T80yDaUX1a




I'm trying to get it to look like this:




site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




I found this post on StackOverflow and tried to implement with amendments I though would work, but the page 500s now.



DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^*.html/(.*)$ /*.html?url=$1 [L,QSA]


This code was added to the pub/.htaccess file.



How do I go about getting the find param into a readable url?










share|improve this question

















This question has an open bounty worth +100
reputation from treyBake ending in 6 days.


This question has not received enough attention.

















  • Did you make all needed setup related to seo url in admin panel?

    – Kirill Korushkin
    21 hours ago











  • @KirillKorushkin not sure I understand - could you please try to clarify? :)

    – treyBake
    21 hours ago











  • are you suing nginx or apache?

    – Philipp Sander
    21 hours ago











  • @PhilippSander Apache :)

    – treyBake
    21 hours ago














0












0








0








I have a URL that looks like this:




site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729&sid=T80yDaUX1a




I'm trying to get it to look like this:




site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




I found this post on StackOverflow and tried to implement with amendments I though would work, but the page 500s now.



DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^*.html/(.*)$ /*.html?url=$1 [L,QSA]


This code was added to the pub/.htaccess file.



How do I go about getting the find param into a readable url?










share|improve this question
















I have a URL that looks like this:




site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729&sid=T80yDaUX1a




I'm trying to get it to look like this:




site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




I found this post on StackOverflow and tried to implement with amendments I though would work, but the page 500s now.



DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^*.html/(.*)$ /*.html?url=$1 [L,QSA]


This code was added to the pub/.htaccess file.



How do I go about getting the find param into a readable url?







magento2 htaccess






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 22 hours ago







treyBake

















asked Jan 18 at 15:02









treyBaketreyBake

187117




187117






This question has an open bounty worth +100
reputation from treyBake ending in 6 days.


This question has not received enough attention.








This question has an open bounty worth +100
reputation from treyBake ending in 6 days.


This question has not received enough attention.















  • Did you make all needed setup related to seo url in admin panel?

    – Kirill Korushkin
    21 hours ago











  • @KirillKorushkin not sure I understand - could you please try to clarify? :)

    – treyBake
    21 hours ago











  • are you suing nginx or apache?

    – Philipp Sander
    21 hours ago











  • @PhilippSander Apache :)

    – treyBake
    21 hours ago



















  • Did you make all needed setup related to seo url in admin panel?

    – Kirill Korushkin
    21 hours ago











  • @KirillKorushkin not sure I understand - could you please try to clarify? :)

    – treyBake
    21 hours ago











  • are you suing nginx or apache?

    – Philipp Sander
    21 hours ago











  • @PhilippSander Apache :)

    – treyBake
    21 hours ago

















Did you make all needed setup related to seo url in admin panel?

– Kirill Korushkin
21 hours ago





Did you make all needed setup related to seo url in admin panel?

– Kirill Korushkin
21 hours ago













@KirillKorushkin not sure I understand - could you please try to clarify? :)

– treyBake
21 hours ago





@KirillKorushkin not sure I understand - could you please try to clarify? :)

– treyBake
21 hours ago













are you suing nginx or apache?

– Philipp Sander
21 hours ago





are you suing nginx or apache?

– Philipp Sander
21 hours ago













@PhilippSander Apache :)

– treyBake
21 hours ago





@PhilippSander Apache :)

– treyBake
21 hours ago










2 Answers
2






active

oldest

votes


















1














By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
In your case, you should create a plugin for URL Rewrite router.
I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:





  1. Create app/code/Vendor/Module/registration.php




<?php

MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);




  1. Create app/code/Vendor/Module/etc/module.xml




<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="0.0.1">
</module>
</config>




  1. Create app/code/Vendor/Module/etc/frontend/di.xml




<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<type name="MagentoUrlRewriteControllerRouter">
<plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
</type>
</config>




  1. Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php




<?php

namespace VendorVendorPluginUrlRewriteController;


class Router
{
public function beforeMatch(
MagentoUrlRewriteControllerRouter $subject,
MagentoFrameworkAppRequestInterface $request
) {
$pathInfo = explode('/', $request->getPathInfo());
if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
$realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
$request->setParam('find', $pathInfo[3]);
$request->setPathInfo($realPathInfo);
}
return [$request];
}
}



  1. Install new module by this command:



php bin/magento setup:upgrade




This module will support to convert the url like




site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




to




site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/




Hope this will solve your issue



Cheers






share|improve this answer

































    0














    Configure URL Rewrites in Magento 2




    • On the Admin Panel, Stores > Settings > Configurations.

    • In the left panel, under General, select Web.

    • Open the Search Engine Optimization section.

    • Select "YES"

    • Clear configuration cache


    source






    share|improve this answer
























    • it's already set to YES

      – treyBake
      20 hours ago











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f258375%2frewrite-url-using-get-params%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
    In your case, you should create a plugin for URL Rewrite router.
    I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:





    1. Create app/code/Vendor/Module/registration.php




    <?php

    MagentoFrameworkComponentComponentRegistrar::register(
    MagentoFrameworkComponentComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__
    );




    1. Create app/code/Vendor/Module/etc/module.xml




    <?xml version="1.0"?>
    <!--
    /**
    * Copyright © Magento, Inc. All rights reserved.
    * See COPYING.txt for license details.
    */
    -->
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="0.0.1">
    </module>
    </config>




    1. Create app/code/Vendor/Module/etc/frontend/di.xml




    <?xml version="1.0"?>
    <!--
    /**
    * Copyright © Magento, Inc. All rights reserved.
    * See COPYING.txt for license details.
    */
    -->
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <type name="MagentoUrlRewriteControllerRouter">
    <plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
    </type>
    </config>




    1. Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php




    <?php

    namespace VendorVendorPluginUrlRewriteController;


    class Router
    {
    public function beforeMatch(
    MagentoUrlRewriteControllerRouter $subject,
    MagentoFrameworkAppRequestInterface $request
    ) {
    $pathInfo = explode('/', $request->getPathInfo());
    if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
    $realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
    $request->setParam('find', $pathInfo[3]);
    $request->setPathInfo($realPathInfo);
    }
    return [$request];
    }
    }



    1. Install new module by this command:



    php bin/magento setup:upgrade




    This module will support to convert the url like




    site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




    to




    site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/




    Hope this will solve your issue



    Cheers






    share|improve this answer






























      1














      By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
      In your case, you should create a plugin for URL Rewrite router.
      I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:





      1. Create app/code/Vendor/Module/registration.php




      <?php

      MagentoFrameworkComponentComponentRegistrar::register(
      MagentoFrameworkComponentComponentRegistrar::MODULE,
      'Vendor_Module',
      __DIR__
      );




      1. Create app/code/Vendor/Module/etc/module.xml




      <?xml version="1.0"?>
      <!--
      /**
      * Copyright © Magento, Inc. All rights reserved.
      * See COPYING.txt for license details.
      */
      -->
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
      <module name="Vendor_Module" setup_version="0.0.1">
      </module>
      </config>




      1. Create app/code/Vendor/Module/etc/frontend/di.xml




      <?xml version="1.0"?>
      <!--
      /**
      * Copyright © Magento, Inc. All rights reserved.
      * See COPYING.txt for license details.
      */
      -->
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
      <type name="MagentoUrlRewriteControllerRouter">
      <plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
      </type>
      </config>




      1. Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php




      <?php

      namespace VendorVendorPluginUrlRewriteController;


      class Router
      {
      public function beforeMatch(
      MagentoUrlRewriteControllerRouter $subject,
      MagentoFrameworkAppRequestInterface $request
      ) {
      $pathInfo = explode('/', $request->getPathInfo());
      if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
      $realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
      $request->setParam('find', $pathInfo[3]);
      $request->setPathInfo($realPathInfo);
      }
      return [$request];
      }
      }



      1. Install new module by this command:



      php bin/magento setup:upgrade




      This module will support to convert the url like




      site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




      to




      site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/




      Hope this will solve your issue



      Cheers






      share|improve this answer




























        1












        1








        1







        By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
        In your case, you should create a plugin for URL Rewrite router.
        I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:





        1. Create app/code/Vendor/Module/registration.php




        <?php

        MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'Vendor_Module',
        __DIR__
        );




        1. Create app/code/Vendor/Module/etc/module.xml




        <?xml version="1.0"?>
        <!--
        /**
        * Copyright © Magento, Inc. All rights reserved.
        * See COPYING.txt for license details.
        */
        -->
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Vendor_Module" setup_version="0.0.1">
        </module>
        </config>




        1. Create app/code/Vendor/Module/etc/frontend/di.xml




        <?xml version="1.0"?>
        <!--
        /**
        * Copyright © Magento, Inc. All rights reserved.
        * See COPYING.txt for license details.
        */
        -->
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <type name="MagentoUrlRewriteControllerRouter">
        <plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
        </type>
        </config>




        1. Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php




        <?php

        namespace VendorVendorPluginUrlRewriteController;


        class Router
        {
        public function beforeMatch(
        MagentoUrlRewriteControllerRouter $subject,
        MagentoFrameworkAppRequestInterface $request
        ) {
        $pathInfo = explode('/', $request->getPathInfo());
        if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
        $realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
        $request->setParam('find', $pathInfo[3]);
        $request->setPathInfo($realPathInfo);
        }
        return [$request];
        }
        }



        1. Install new module by this command:



        php bin/magento setup:upgrade




        This module will support to convert the url like




        site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




        to




        site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/




        Hope this will solve your issue



        Cheers






        share|improve this answer















        By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
        In your case, you should create a plugin for URL Rewrite router.
        I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:





        1. Create app/code/Vendor/Module/registration.php




        <?php

        MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'Vendor_Module',
        __DIR__
        );




        1. Create app/code/Vendor/Module/etc/module.xml




        <?xml version="1.0"?>
        <!--
        /**
        * Copyright © Magento, Inc. All rights reserved.
        * See COPYING.txt for license details.
        */
        -->
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Vendor_Module" setup_version="0.0.1">
        </module>
        </config>




        1. Create app/code/Vendor/Module/etc/frontend/di.xml




        <?xml version="1.0"?>
        <!--
        /**
        * Copyright © Magento, Inc. All rights reserved.
        * See COPYING.txt for license details.
        */
        -->
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <type name="MagentoUrlRewriteControllerRouter">
        <plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
        </type>
        </config>




        1. Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php




        <?php

        namespace VendorVendorPluginUrlRewriteController;


        class Router
        {
        public function beforeMatch(
        MagentoUrlRewriteControllerRouter $subject,
        MagentoFrameworkAppRequestInterface $request
        ) {
        $pathInfo = explode('/', $request->getPathInfo());
        if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
        $realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
        $request->setParam('find', $pathInfo[3]);
        $request->setPathInfo($realPathInfo);
        }
        return [$request];
        }
        }



        1. Install new module by this command:



        php bin/magento setup:upgrade




        This module will support to convert the url like




        site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/




        to




        site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/




        Hope this will solve your issue



        Cheers







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 hours ago









        bachlee89

        253




        253










        answered 2 hours ago









        BabonBabon

        7328




        7328

























            0














            Configure URL Rewrites in Magento 2




            • On the Admin Panel, Stores > Settings > Configurations.

            • In the left panel, under General, select Web.

            • Open the Search Engine Optimization section.

            • Select "YES"

            • Clear configuration cache


            source






            share|improve this answer
























            • it's already set to YES

              – treyBake
              20 hours ago
















            0














            Configure URL Rewrites in Magento 2




            • On the Admin Panel, Stores > Settings > Configurations.

            • In the left panel, under General, select Web.

            • Open the Search Engine Optimization section.

            • Select "YES"

            • Clear configuration cache


            source






            share|improve this answer
























            • it's already set to YES

              – treyBake
              20 hours ago














            0












            0








            0







            Configure URL Rewrites in Magento 2




            • On the Admin Panel, Stores > Settings > Configurations.

            • In the left panel, under General, select Web.

            • Open the Search Engine Optimization section.

            • Select "YES"

            • Clear configuration cache


            source






            share|improve this answer













            Configure URL Rewrites in Magento 2




            • On the Admin Panel, Stores > Settings > Configurations.

            • In the left panel, under General, select Web.

            • Open the Search Engine Optimization section.

            • Select "YES"

            • Clear configuration cache


            source







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 21 hours ago









            Philipp SanderPhilipp Sander

            4091419




            4091419













            • it's already set to YES

              – treyBake
              20 hours ago



















            • it's already set to YES

              – treyBake
              20 hours ago

















            it's already set to YES

            – treyBake
            20 hours ago





            it's already set to YES

            – treyBake
            20 hours ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f258375%2frewrite-url-using-get-params%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1300-talet

            1300-talet

            Display a custom attribute below product name in the front-end Magento 1.9.3.8