.htaccess redirect with multiple hypens in url












0














we have move our website and decided to remove all the old news, if is there a way to redirect urls which contain '-'



here is an example of some fo the URLs we have redirect.



RedirectMatch 301 /climate-change-threatens-expose-cold-war-secrets/?$ /news



RedirectMatch 301 /countdown-to-armed-forces-day-begins-in-liverpool/?$ /news



RedirectMatch 301 /chilcot-report-the-key-findings/?$ /news



RedirectMatch 301 /cold-war-nuclear-base-uncovered-ice-melts/?$ /news



RedirectMatch 301 /corbyn-refuses-guarantee-support-nato-allies/?$ /news



RedirectMatch 301 /comment-if-were-in-a-cold-war-how-do-we-get-out/?$ /news



Is it possible to redirect anything with along these lines "word1-word2-word3-OrEvenMoreWords"



Thanks










share|improve this question







New contributor




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

























    0














    we have move our website and decided to remove all the old news, if is there a way to redirect urls which contain '-'



    here is an example of some fo the URLs we have redirect.



    RedirectMatch 301 /climate-change-threatens-expose-cold-war-secrets/?$ /news



    RedirectMatch 301 /countdown-to-armed-forces-day-begins-in-liverpool/?$ /news



    RedirectMatch 301 /chilcot-report-the-key-findings/?$ /news



    RedirectMatch 301 /cold-war-nuclear-base-uncovered-ice-melts/?$ /news



    RedirectMatch 301 /corbyn-refuses-guarantee-support-nato-allies/?$ /news



    RedirectMatch 301 /comment-if-were-in-a-cold-war-how-do-we-get-out/?$ /news



    Is it possible to redirect anything with along these lines "word1-word2-word3-OrEvenMoreWords"



    Thanks










    share|improve this question







    New contributor




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























      0












      0








      0







      we have move our website and decided to remove all the old news, if is there a way to redirect urls which contain '-'



      here is an example of some fo the URLs we have redirect.



      RedirectMatch 301 /climate-change-threatens-expose-cold-war-secrets/?$ /news



      RedirectMatch 301 /countdown-to-armed-forces-day-begins-in-liverpool/?$ /news



      RedirectMatch 301 /chilcot-report-the-key-findings/?$ /news



      RedirectMatch 301 /cold-war-nuclear-base-uncovered-ice-melts/?$ /news



      RedirectMatch 301 /corbyn-refuses-guarantee-support-nato-allies/?$ /news



      RedirectMatch 301 /comment-if-were-in-a-cold-war-how-do-we-get-out/?$ /news



      Is it possible to redirect anything with along these lines "word1-word2-word3-OrEvenMoreWords"



      Thanks










      share|improve this question







      New contributor




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











      we have move our website and decided to remove all the old news, if is there a way to redirect urls which contain '-'



      here is an example of some fo the URLs we have redirect.



      RedirectMatch 301 /climate-change-threatens-expose-cold-war-secrets/?$ /news



      RedirectMatch 301 /countdown-to-armed-forces-day-begins-in-liverpool/?$ /news



      RedirectMatch 301 /chilcot-report-the-key-findings/?$ /news



      RedirectMatch 301 /cold-war-nuclear-base-uncovered-ice-melts/?$ /news



      RedirectMatch 301 /corbyn-refuses-guarantee-support-nato-allies/?$ /news



      RedirectMatch 301 /comment-if-were-in-a-cold-war-how-do-we-get-out/?$ /news



      Is it possible to redirect anything with along these lines "word1-word2-word3-OrEvenMoreWords"



      Thanks







      .htaccess redirect






      share|improve this question







      New contributor




      DaveWilliamson 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




      DaveWilliamson 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




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









      asked yesterday









      DaveWilliamson

      11




      11




      New contributor




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





      New contributor





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






      DaveWilliamson 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


















          0














          If there are at least 2 words separated by - per news post then the following should be sufficient:



          RedirectMatch 301 ^[^-]+(?:-[^-]+)+$ /news   # matches "my-post" or "my-long-post" but not "mypost" or "my--post"


          ^ matches the start of the URL.
          [^-] matches all except for -.
          + keeps matching the previous rule and ensures at least one is matched.
          (?: begins a non-capturing group.

               - matches the - character.

               [^-] matches all except for -.

               + keeps matching the previous rule and ensures at least one is matched.
          ) ends the non-capturing group.
          + keeps repeating the non-capturing group ensuring it is matched at least once - the group begins with - and matches at least one character up to the next - so in this way we allow a-b-c-d...
          $ matches the end of the URL, ensuring nothing remains unparsed.






          share|improve this answer























          • thank you I am new to this so could you point me in the right direct so I can understand what that all means. Many Thanks
            – DaveWilliamson
            yesterday










          • The regex itself or the entire .htaccess line? I assumed you were familiar with them since you give your own examples in both. For the regex part you could check out regex101.com to test the regex with your own input and get a brief explanation of what each part does and how it matches the input. There are many more sources for more detailed information on regex though, you'll have to Google around if you want more on that.
            – Deji
            yesterday










          • Many Thanks for this I will look there now.
            – DaveWilliamson
            yesterday











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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
          });


          }
          });






          DaveWilliamson 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%2fstackoverflow.com%2fquestions%2f53944126%2fhtaccess-redirect-with-multiple-hypens-in-url%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If there are at least 2 words separated by - per news post then the following should be sufficient:



          RedirectMatch 301 ^[^-]+(?:-[^-]+)+$ /news   # matches "my-post" or "my-long-post" but not "mypost" or "my--post"


          ^ matches the start of the URL.
          [^-] matches all except for -.
          + keeps matching the previous rule and ensures at least one is matched.
          (?: begins a non-capturing group.

               - matches the - character.

               [^-] matches all except for -.

               + keeps matching the previous rule and ensures at least one is matched.
          ) ends the non-capturing group.
          + keeps repeating the non-capturing group ensuring it is matched at least once - the group begins with - and matches at least one character up to the next - so in this way we allow a-b-c-d...
          $ matches the end of the URL, ensuring nothing remains unparsed.






          share|improve this answer























          • thank you I am new to this so could you point me in the right direct so I can understand what that all means. Many Thanks
            – DaveWilliamson
            yesterday










          • The regex itself or the entire .htaccess line? I assumed you were familiar with them since you give your own examples in both. For the regex part you could check out regex101.com to test the regex with your own input and get a brief explanation of what each part does and how it matches the input. There are many more sources for more detailed information on regex though, you'll have to Google around if you want more on that.
            – Deji
            yesterday










          • Many Thanks for this I will look there now.
            – DaveWilliamson
            yesterday
















          0














          If there are at least 2 words separated by - per news post then the following should be sufficient:



          RedirectMatch 301 ^[^-]+(?:-[^-]+)+$ /news   # matches "my-post" or "my-long-post" but not "mypost" or "my--post"


          ^ matches the start of the URL.
          [^-] matches all except for -.
          + keeps matching the previous rule and ensures at least one is matched.
          (?: begins a non-capturing group.

               - matches the - character.

               [^-] matches all except for -.

               + keeps matching the previous rule and ensures at least one is matched.
          ) ends the non-capturing group.
          + keeps repeating the non-capturing group ensuring it is matched at least once - the group begins with - and matches at least one character up to the next - so in this way we allow a-b-c-d...
          $ matches the end of the URL, ensuring nothing remains unparsed.






          share|improve this answer























          • thank you I am new to this so could you point me in the right direct so I can understand what that all means. Many Thanks
            – DaveWilliamson
            yesterday










          • The regex itself or the entire .htaccess line? I assumed you were familiar with them since you give your own examples in both. For the regex part you could check out regex101.com to test the regex with your own input and get a brief explanation of what each part does and how it matches the input. There are many more sources for more detailed information on regex though, you'll have to Google around if you want more on that.
            – Deji
            yesterday










          • Many Thanks for this I will look there now.
            – DaveWilliamson
            yesterday














          0












          0








          0






          If there are at least 2 words separated by - per news post then the following should be sufficient:



          RedirectMatch 301 ^[^-]+(?:-[^-]+)+$ /news   # matches "my-post" or "my-long-post" but not "mypost" or "my--post"


          ^ matches the start of the URL.
          [^-] matches all except for -.
          + keeps matching the previous rule and ensures at least one is matched.
          (?: begins a non-capturing group.

               - matches the - character.

               [^-] matches all except for -.

               + keeps matching the previous rule and ensures at least one is matched.
          ) ends the non-capturing group.
          + keeps repeating the non-capturing group ensuring it is matched at least once - the group begins with - and matches at least one character up to the next - so in this way we allow a-b-c-d...
          $ matches the end of the URL, ensuring nothing remains unparsed.






          share|improve this answer














          If there are at least 2 words separated by - per news post then the following should be sufficient:



          RedirectMatch 301 ^[^-]+(?:-[^-]+)+$ /news   # matches "my-post" or "my-long-post" but not "mypost" or "my--post"


          ^ matches the start of the URL.
          [^-] matches all except for -.
          + keeps matching the previous rule and ensures at least one is matched.
          (?: begins a non-capturing group.

               - matches the - character.

               [^-] matches all except for -.

               + keeps matching the previous rule and ensures at least one is matched.
          ) ends the non-capturing group.
          + keeps repeating the non-capturing group ensuring it is matched at least once - the group begins with - and matches at least one character up to the next - so in this way we allow a-b-c-d...
          $ matches the end of the URL, ensuring nothing remains unparsed.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          Deji

          5231615




          5231615












          • thank you I am new to this so could you point me in the right direct so I can understand what that all means. Many Thanks
            – DaveWilliamson
            yesterday










          • The regex itself or the entire .htaccess line? I assumed you were familiar with them since you give your own examples in both. For the regex part you could check out regex101.com to test the regex with your own input and get a brief explanation of what each part does and how it matches the input. There are many more sources for more detailed information on regex though, you'll have to Google around if you want more on that.
            – Deji
            yesterday










          • Many Thanks for this I will look there now.
            – DaveWilliamson
            yesterday


















          • thank you I am new to this so could you point me in the right direct so I can understand what that all means. Many Thanks
            – DaveWilliamson
            yesterday










          • The regex itself or the entire .htaccess line? I assumed you were familiar with them since you give your own examples in both. For the regex part you could check out regex101.com to test the regex with your own input and get a brief explanation of what each part does and how it matches the input. There are many more sources for more detailed information on regex though, you'll have to Google around if you want more on that.
            – Deji
            yesterday










          • Many Thanks for this I will look there now.
            – DaveWilliamson
            yesterday
















          thank you I am new to this so could you point me in the right direct so I can understand what that all means. Many Thanks
          – DaveWilliamson
          yesterday




          thank you I am new to this so could you point me in the right direct so I can understand what that all means. Many Thanks
          – DaveWilliamson
          yesterday












          The regex itself or the entire .htaccess line? I assumed you were familiar with them since you give your own examples in both. For the regex part you could check out regex101.com to test the regex with your own input and get a brief explanation of what each part does and how it matches the input. There are many more sources for more detailed information on regex though, you'll have to Google around if you want more on that.
          – Deji
          yesterday




          The regex itself or the entire .htaccess line? I assumed you were familiar with them since you give your own examples in both. For the regex part you could check out regex101.com to test the regex with your own input and get a brief explanation of what each part does and how it matches the input. There are many more sources for more detailed information on regex though, you'll have to Google around if you want more on that.
          – Deji
          yesterday












          Many Thanks for this I will look there now.
          – DaveWilliamson
          yesterday




          Many Thanks for this I will look there now.
          – DaveWilliamson
          yesterday










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










          draft saved

          draft discarded


















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













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












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
















          Thanks for contributing an answer to Stack Overflow!


          • 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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2fstackoverflow.com%2fquestions%2f53944126%2fhtaccess-redirect-with-multiple-hypens-in-url%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

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'