Multiple hyphen handling in .htaccess (URL rewriting)












1















I have a problem with URL rewriting. I have written the following rule in my .htaccess file



RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2


It gives me URLs like that : http://localhost/actuco/c-628Y8x-france/ (featuring the ID of the category, and its slug). This URL works perfectly.



But, when I type this URL : http://localhost/actuco/c-xpS3cc-amerique-du-nord/
it doesn't works anymore. The cause of the problem must be the fact that the latter slug contains several hyphens (amerique-du-nord) whereas the first one (france) contains no hyphens at all (I tried with all my categories with slugs including multiple hyphens).



Does anyone know how to solve this please ?



Here is my complete .htaccess code



Options +FollowSymlinks

RewriteEngine On

RewriteBase /actuco/
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} /+[^.]+$
#RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ article.php?lng=$1&yr=$2&mo=$3&dy=$4&slug=$5&total_slug=$6
#RewriteRule ^([^/]*)-([^/]*)-([^/]*)$ waluty.php?cur=$1&amt=$2&lang=$3
RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
RewriteRule ^([^/]*)/([^/]*)/$ url.php?mode=$1&u=$2
RewriteRule ^bio$ o.php [L]


Thanks in advance !










share|improve this question





























    1















    I have a problem with URL rewriting. I have written the following rule in my .htaccess file



    RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2


    It gives me URLs like that : http://localhost/actuco/c-628Y8x-france/ (featuring the ID of the category, and its slug). This URL works perfectly.



    But, when I type this URL : http://localhost/actuco/c-xpS3cc-amerique-du-nord/
    it doesn't works anymore. The cause of the problem must be the fact that the latter slug contains several hyphens (amerique-du-nord) whereas the first one (france) contains no hyphens at all (I tried with all my categories with slugs including multiple hyphens).



    Does anyone know how to solve this please ?



    Here is my complete .htaccess code



    Options +FollowSymlinks

    RewriteEngine On

    RewriteBase /actuco/
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_URI} /+[^.]+$
    #RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ article.php?lng=$1&yr=$2&mo=$3&dy=$4&slug=$5&total_slug=$6
    #RewriteRule ^([^/]*)-([^/]*)-([^/]*)$ waluty.php?cur=$1&amt=$2&lang=$3
    RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
    RewriteRule ^([^/]*)/([^/]*)/$ url.php?mode=$1&u=$2
    RewriteRule ^bio$ o.php [L]


    Thanks in advance !










    share|improve this question



























      1












      1








      1








      I have a problem with URL rewriting. I have written the following rule in my .htaccess file



      RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2


      It gives me URLs like that : http://localhost/actuco/c-628Y8x-france/ (featuring the ID of the category, and its slug). This URL works perfectly.



      But, when I type this URL : http://localhost/actuco/c-xpS3cc-amerique-du-nord/
      it doesn't works anymore. The cause of the problem must be the fact that the latter slug contains several hyphens (amerique-du-nord) whereas the first one (france) contains no hyphens at all (I tried with all my categories with slugs including multiple hyphens).



      Does anyone know how to solve this please ?



      Here is my complete .htaccess code



      Options +FollowSymlinks

      RewriteEngine On

      RewriteBase /actuco/
      #RewriteCond %{REQUEST_FILENAME} !-f
      #RewriteCond %{REQUEST_URI} /+[^.]+$
      #RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
      RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ article.php?lng=$1&yr=$2&mo=$3&dy=$4&slug=$5&total_slug=$6
      #RewriteRule ^([^/]*)-([^/]*)-([^/]*)$ waluty.php?cur=$1&amt=$2&lang=$3
      RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
      RewriteRule ^([^/]*)/([^/]*)/$ url.php?mode=$1&u=$2
      RewriteRule ^bio$ o.php [L]


      Thanks in advance !










      share|improve this question
















      I have a problem with URL rewriting. I have written the following rule in my .htaccess file



      RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2


      It gives me URLs like that : http://localhost/actuco/c-628Y8x-france/ (featuring the ID of the category, and its slug). This URL works perfectly.



      But, when I type this URL : http://localhost/actuco/c-xpS3cc-amerique-du-nord/
      it doesn't works anymore. The cause of the problem must be the fact that the latter slug contains several hyphens (amerique-du-nord) whereas the first one (france) contains no hyphens at all (I tried with all my categories with slugs including multiple hyphens).



      Does anyone know how to solve this please ?



      Here is my complete .htaccess code



      Options +FollowSymlinks

      RewriteEngine On

      RewriteBase /actuco/
      #RewriteCond %{REQUEST_FILENAME} !-f
      #RewriteCond %{REQUEST_URI} /+[^.]+$
      #RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
      RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ article.php?lng=$1&yr=$2&mo=$3&dy=$4&slug=$5&total_slug=$6
      #RewriteRule ^([^/]*)-([^/]*)-([^/]*)$ waluty.php?cur=$1&amt=$2&lang=$3
      RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
      RewriteRule ^([^/]*)/([^/]*)/$ url.php?mode=$1&u=$2
      RewriteRule ^bio$ o.php [L]


      Thanks in advance !







      .htaccess url-rewriting slug






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 21:07









      miken32

      23.6k84872




      23.6k84872










      asked Nov 13 '18 at 20:08









      Bara KudaBara Kuda

      207




      207
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can try:



          RewriteRule ^c-([w]+)-([w-]+)/$ cat.php?id=$1&slug=$2





          share|improve this answer
























          • Works perfectly, thanks ! Could you explain please what the antislashes and "w" stand for ?

            – Bara Kuda
            Nov 13 '18 at 20:57






          • 1





            You're welcome! Sure, w is a metacharacter in regexp, it stands for every standard letter and digit and the underscore character. The other antislashes were used for 'escaping' functional characters, like - or /.

            – Dan D.
            Nov 13 '18 at 21:26











          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288730%2fmultiple-hyphen-handling-in-htaccess-url-rewriting%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









          1














          You can try:



          RewriteRule ^c-([w]+)-([w-]+)/$ cat.php?id=$1&slug=$2





          share|improve this answer
























          • Works perfectly, thanks ! Could you explain please what the antislashes and "w" stand for ?

            – Bara Kuda
            Nov 13 '18 at 20:57






          • 1





            You're welcome! Sure, w is a metacharacter in regexp, it stands for every standard letter and digit and the underscore character. The other antislashes were used for 'escaping' functional characters, like - or /.

            – Dan D.
            Nov 13 '18 at 21:26
















          1














          You can try:



          RewriteRule ^c-([w]+)-([w-]+)/$ cat.php?id=$1&slug=$2





          share|improve this answer
























          • Works perfectly, thanks ! Could you explain please what the antislashes and "w" stand for ?

            – Bara Kuda
            Nov 13 '18 at 20:57






          • 1





            You're welcome! Sure, w is a metacharacter in regexp, it stands for every standard letter and digit and the underscore character. The other antislashes were used for 'escaping' functional characters, like - or /.

            – Dan D.
            Nov 13 '18 at 21:26














          1












          1








          1







          You can try:



          RewriteRule ^c-([w]+)-([w-]+)/$ cat.php?id=$1&slug=$2





          share|improve this answer













          You can try:



          RewriteRule ^c-([w]+)-([w-]+)/$ cat.php?id=$1&slug=$2






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 20:39









          Dan D.Dan D.

          570213




          570213













          • Works perfectly, thanks ! Could you explain please what the antislashes and "w" stand for ?

            – Bara Kuda
            Nov 13 '18 at 20:57






          • 1





            You're welcome! Sure, w is a metacharacter in regexp, it stands for every standard letter and digit and the underscore character. The other antislashes were used for 'escaping' functional characters, like - or /.

            – Dan D.
            Nov 13 '18 at 21:26



















          • Works perfectly, thanks ! Could you explain please what the antislashes and "w" stand for ?

            – Bara Kuda
            Nov 13 '18 at 20:57






          • 1





            You're welcome! Sure, w is a metacharacter in regexp, it stands for every standard letter and digit and the underscore character. The other antislashes were used for 'escaping' functional characters, like - or /.

            – Dan D.
            Nov 13 '18 at 21:26

















          Works perfectly, thanks ! Could you explain please what the antislashes and "w" stand for ?

          – Bara Kuda
          Nov 13 '18 at 20:57





          Works perfectly, thanks ! Could you explain please what the antislashes and "w" stand for ?

          – Bara Kuda
          Nov 13 '18 at 20:57




          1




          1





          You're welcome! Sure, w is a metacharacter in regexp, it stands for every standard letter and digit and the underscore character. The other antislashes were used for 'escaping' functional characters, like - or /.

          – Dan D.
          Nov 13 '18 at 21:26





          You're welcome! Sure, w is a metacharacter in regexp, it stands for every standard letter and digit and the underscore character. The other antislashes were used for 'escaping' functional characters, like - or /.

          – Dan D.
          Nov 13 '18 at 21:26


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288730%2fmultiple-hyphen-handling-in-htaccess-url-rewriting%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

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python