Nginx simple redirect of products from old to new category

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I'm making redirects of products from old to new category.



I've managed to make it work with following rule:



rewrite ^/old-category/(.*) /new-category/$1;


But I want to know when should I use "end line" sign $ and what's the difference with it or without it in my case. For example:



rewrite ^/old-category/(.*)$ /new-category/$1;


Also I want to redirect users if they simply write old category name (without products), should I create a new rule just for category redirect or I can edit the current rule above to work in both cases.



Thank you for your answers in advance.










share|improve this question







New contributor




Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    2
    down vote

    favorite












    I'm making redirects of products from old to new category.



    I've managed to make it work with following rule:



    rewrite ^/old-category/(.*) /new-category/$1;


    But I want to know when should I use "end line" sign $ and what's the difference with it or without it in my case. For example:



    rewrite ^/old-category/(.*)$ /new-category/$1;


    Also I want to redirect users if they simply write old category name (without products), should I create a new rule just for category redirect or I can edit the current rule above to work in both cases.



    Thank you for your answers in advance.










    share|improve this question







    New contributor




    Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'm making redirects of products from old to new category.



      I've managed to make it work with following rule:



      rewrite ^/old-category/(.*) /new-category/$1;


      But I want to know when should I use "end line" sign $ and what's the difference with it or without it in my case. For example:



      rewrite ^/old-category/(.*)$ /new-category/$1;


      Also I want to redirect users if they simply write old category name (without products), should I create a new rule just for category redirect or I can edit the current rule above to work in both cases.



      Thank you for your answers in advance.










      share|improve this question







      New contributor




      Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm making redirects of products from old to new category.



      I've managed to make it work with following rule:



      rewrite ^/old-category/(.*) /new-category/$1;


      But I want to know when should I use "end line" sign $ and what's the difference with it or without it in my case. For example:



      rewrite ^/old-category/(.*)$ /new-category/$1;


      Also I want to redirect users if they simply write old category name (without products), should I create a new rule just for category redirect or I can edit the current rule above to work in both cases.



      Thank you for your answers in advance.







      nginx redirect rewrite






      share|improve this question







      New contributor




      Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 hours ago









      Analogtime

      111




      111




      New contributor




      Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Hello and welcome to Server Fault.



          Answering your questions in order...



          This



          rewrite ^/old-category/(.*) /new-category/$1;


          and this



          rewrite ^/old-category/(.*)$ /new-category/$1;


          as written are equivalent. The .* rule matches 0 or more of "everything".



          The $ terminator is useful when you want to match strings that end in a specific way, for example



          rewrite ^/old-category/(.*).php$ /new-category/$1;


          to rewrite only PHP files.



          As for your second question, if I understood correctly, you want to redirect this



          http://example.com/old-category/


          to this



          http://example.com/new-category/


          If that's so, it's already done by the rewrite rule, as .* matches ZERO or more characters.






          share|improve this answer




















          • Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
            – Broco
            42 mins ago











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "2"
          ;
          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',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Analogtime is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f934465%2fnginx-simple-redirect-of-products-from-old-to-new-category%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          Hello and welcome to Server Fault.



          Answering your questions in order...



          This



          rewrite ^/old-category/(.*) /new-category/$1;


          and this



          rewrite ^/old-category/(.*)$ /new-category/$1;


          as written are equivalent. The .* rule matches 0 or more of "everything".



          The $ terminator is useful when you want to match strings that end in a specific way, for example



          rewrite ^/old-category/(.*).php$ /new-category/$1;


          to rewrite only PHP files.



          As for your second question, if I understood correctly, you want to redirect this



          http://example.com/old-category/


          to this



          http://example.com/new-category/


          If that's so, it's already done by the rewrite rule, as .* matches ZERO or more characters.






          share|improve this answer




















          • Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
            – Broco
            42 mins ago















          up vote
          2
          down vote













          Hello and welcome to Server Fault.



          Answering your questions in order...



          This



          rewrite ^/old-category/(.*) /new-category/$1;


          and this



          rewrite ^/old-category/(.*)$ /new-category/$1;


          as written are equivalent. The .* rule matches 0 or more of "everything".



          The $ terminator is useful when you want to match strings that end in a specific way, for example



          rewrite ^/old-category/(.*).php$ /new-category/$1;


          to rewrite only PHP files.



          As for your second question, if I understood correctly, you want to redirect this



          http://example.com/old-category/


          to this



          http://example.com/new-category/


          If that's so, it's already done by the rewrite rule, as .* matches ZERO or more characters.






          share|improve this answer




















          • Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
            – Broco
            42 mins ago













          up vote
          2
          down vote










          up vote
          2
          down vote









          Hello and welcome to Server Fault.



          Answering your questions in order...



          This



          rewrite ^/old-category/(.*) /new-category/$1;


          and this



          rewrite ^/old-category/(.*)$ /new-category/$1;


          as written are equivalent. The .* rule matches 0 or more of "everything".



          The $ terminator is useful when you want to match strings that end in a specific way, for example



          rewrite ^/old-category/(.*).php$ /new-category/$1;


          to rewrite only PHP files.



          As for your second question, if I understood correctly, you want to redirect this



          http://example.com/old-category/


          to this



          http://example.com/new-category/


          If that's so, it's already done by the rewrite rule, as .* matches ZERO or more characters.






          share|improve this answer












          Hello and welcome to Server Fault.



          Answering your questions in order...



          This



          rewrite ^/old-category/(.*) /new-category/$1;


          and this



          rewrite ^/old-category/(.*)$ /new-category/$1;


          as written are equivalent. The .* rule matches 0 or more of "everything".



          The $ terminator is useful when you want to match strings that end in a specific way, for example



          rewrite ^/old-category/(.*).php$ /new-category/$1;


          to rewrite only PHP files.



          As for your second question, if I understood correctly, you want to redirect this



          http://example.com/old-category/


          to this



          http://example.com/new-category/


          If that's so, it's already done by the rewrite rule, as .* matches ZERO or more characters.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 52 mins ago









          Mr Shunz

          2,06111819




          2,06111819











          • Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
            – Broco
            42 mins ago

















          • Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
            – Broco
            42 mins ago
















          Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
          – Broco
          42 mins ago





          Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
          – Broco
          42 mins ago











          Analogtime is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Analogtime is a new contributor. Be nice, and check out our Code of Conduct.












          Analogtime is a new contributor. Be nice, and check out our Code of Conduct.











          Analogtime is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f934465%2fnginx-simple-redirect-of-products-from-old-to-new-category%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          Confectionery