.htaccess redirects aren't respecting my regex The Next CEO of Stack OverflowCheck to see if a key exists in a query string - htaccesshtaccess rewrite to include #!htaccess QUERY_STRING urldecodeAllow multiple IPs to access Wordpress Site Admin via .htaccesshtaccess redirect if index.php is missing301 htaccess redirect dynamic URL in a subfolder to home page.htaccess redirect with unique url AND query stringhtaccess query string redirect not workingMultiple languages + Htaccess404 issue in two htaccess in root domain and subfoler

What is the point of a new vote on May's deal when the indicative votes suggest she will not win?

Are there languages with no euphemisms?

How do I construct this japanese bowl?

How to be diplomatic in refusing to write code that breaches the privacy of our users

How to Reset Passwords on Multiple Websites Easily?

Why do professional authors make "consistency" mistakes? And how to avoid them?

Go Pregnant or Go Home

How do I go from 300 unfinished/half written blog posts, to published posts?

What is the purpose of the Evocation wizard's Potent Cantrip feature?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Why were Madagascar and New Zealand discovered so late?

Natural language into sentence logic

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

Opposite of a diet

Fastest way to shutdown Ubuntu Mate 18.10

Is it okay to store user locations?

How easy is it to start Magic from scratch?

Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables

Why didn't Khan get resurrected in the Genesis Explosion?

How to count occurrences of text in a file?

How to make a software documentation "officially" citable?

MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs

Why did we only see the N-1 starfighters in one film?

Grabbing quick drinks



.htaccess redirects aren't respecting my regex



The Next CEO of Stack OverflowCheck to see if a key exists in a query string - htaccesshtaccess rewrite to include #!htaccess QUERY_STRING urldecodeAllow multiple IPs to access Wordpress Site Admin via .htaccesshtaccess redirect if index.php is missing301 htaccess redirect dynamic URL in a subfolder to home page.htaccess redirect with unique url AND query stringhtaccess query string redirect not workingMultiple languages + Htaccess404 issue in two htaccess in root domain and subfoler










0















I need to redirect any requests with query strings from a set of origin URLs back to a thank you page.



For example, I need to redirect:
http://example.com/test1/test2/[origin]/?id=1

back to
http://example.com/thank-you



The way I've got it set up in my .htaccess file is as such:



RewriteEngine On
RedirectMatch 302 ^/test1/test2/(.*)/.+ /thank-you


I've tested the regex I'm using in an online regex tester and it appears to work as expected, so I'm confused as to why the redirect isn't taking place. Here's the link to that.



Obviously, I had to add backslashes to escape the slashes in the URL in the regex tester, but based on my understanding of how .htaccess evaluates regex, these aren't necessary.



My question is: the redirect works perfectly from the page without the query string if I remove the .+ from the end of the regex string, meaning that the beginning part of the regex works fine. I don't understand why the query string isn't matching the regex I've created.



I have also tried:



RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L]









share|improve this question
























  • No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.

    – IanCZane
    Mar 21 at 17:16






  • 1





    Your second set of code (RewriteRule) could work with flags [R=302,L,QSD].

    – AdminOfThings
    Mar 21 at 18:50












  • @IanCZane your second rules , only add ? after target thank-you like this thank-you?

    – Mohammed Elhag
    Mar 21 at 19:07















0















I need to redirect any requests with query strings from a set of origin URLs back to a thank you page.



For example, I need to redirect:
http://example.com/test1/test2/[origin]/?id=1

back to
http://example.com/thank-you



The way I've got it set up in my .htaccess file is as such:



RewriteEngine On
RedirectMatch 302 ^/test1/test2/(.*)/.+ /thank-you


I've tested the regex I'm using in an online regex tester and it appears to work as expected, so I'm confused as to why the redirect isn't taking place. Here's the link to that.



Obviously, I had to add backslashes to escape the slashes in the URL in the regex tester, but based on my understanding of how .htaccess evaluates regex, these aren't necessary.



My question is: the redirect works perfectly from the page without the query string if I remove the .+ from the end of the regex string, meaning that the beginning part of the regex works fine. I don't understand why the query string isn't matching the regex I've created.



I have also tried:



RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L]









share|improve this question
























  • No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.

    – IanCZane
    Mar 21 at 17:16






  • 1





    Your second set of code (RewriteRule) could work with flags [R=302,L,QSD].

    – AdminOfThings
    Mar 21 at 18:50












  • @IanCZane your second rules , only add ? after target thank-you like this thank-you?

    – Mohammed Elhag
    Mar 21 at 19:07













0












0








0








I need to redirect any requests with query strings from a set of origin URLs back to a thank you page.



For example, I need to redirect:
http://example.com/test1/test2/[origin]/?id=1

back to
http://example.com/thank-you



The way I've got it set up in my .htaccess file is as such:



RewriteEngine On
RedirectMatch 302 ^/test1/test2/(.*)/.+ /thank-you


I've tested the regex I'm using in an online regex tester and it appears to work as expected, so I'm confused as to why the redirect isn't taking place. Here's the link to that.



Obviously, I had to add backslashes to escape the slashes in the URL in the regex tester, but based on my understanding of how .htaccess evaluates regex, these aren't necessary.



My question is: the redirect works perfectly from the page without the query string if I remove the .+ from the end of the regex string, meaning that the beginning part of the regex works fine. I don't understand why the query string isn't matching the regex I've created.



I have also tried:



RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L]









share|improve this question
















I need to redirect any requests with query strings from a set of origin URLs back to a thank you page.



For example, I need to redirect:
http://example.com/test1/test2/[origin]/?id=1

back to
http://example.com/thank-you



The way I've got it set up in my .htaccess file is as such:



RewriteEngine On
RedirectMatch 302 ^/test1/test2/(.*)/.+ /thank-you


I've tested the regex I'm using in an online regex tester and it appears to work as expected, so I'm confused as to why the redirect isn't taking place. Here's the link to that.



Obviously, I had to add backslashes to escape the slashes in the URL in the regex tester, but based on my understanding of how .htaccess evaluates regex, these aren't necessary.



My question is: the redirect works perfectly from the page without the query string if I remove the .+ from the end of the regex string, meaning that the beginning part of the regex works fine. I don't understand why the query string isn't matching the regex I've created.



I have also tried:



RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L]






regex .htaccess query-string






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 17:17







IanCZane

















asked Mar 21 at 16:36









IanCZaneIanCZane

12012




12012












  • No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.

    – IanCZane
    Mar 21 at 17:16






  • 1





    Your second set of code (RewriteRule) could work with flags [R=302,L,QSD].

    – AdminOfThings
    Mar 21 at 18:50












  • @IanCZane your second rules , only add ? after target thank-you like this thank-you?

    – Mohammed Elhag
    Mar 21 at 19:07

















  • No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.

    – IanCZane
    Mar 21 at 17:16






  • 1





    Your second set of code (RewriteRule) could work with flags [R=302,L,QSD].

    – AdminOfThings
    Mar 21 at 18:50












  • @IanCZane your second rules , only add ? after target thank-you like this thank-you?

    – Mohammed Elhag
    Mar 21 at 19:07
















No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.

– IanCZane
Mar 21 at 17:16





No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.

– IanCZane
Mar 21 at 17:16




1




1





Your second set of code (RewriteRule) could work with flags [R=302,L,QSD].

– AdminOfThings
Mar 21 at 18:50






Your second set of code (RewriteRule) could work with flags [R=302,L,QSD].

– AdminOfThings
Mar 21 at 18:50














@IanCZane your second rules , only add ? after target thank-you like this thank-you?

– Mohammed Elhag
Mar 21 at 19:07





@IanCZane your second rules , only add ? after target thank-you like this thank-you?

– Mohammed Elhag
Mar 21 at 19:07












2 Answers
2






active

oldest

votes


















0














First , no need to RewriteEngine On with mod_alias which is RedirectMatch at your rules use it with mod_rewrite , the second rules .



Try this :



RewriteEngine On
RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]


I use ^id=([0-9]+)$ to restrict query string for a one that start with id and end with numerical value.



I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/ becasue you could match against URI in RewriteRule as well.



If this rules wrok , change [R=302,L] to [R=301,L] to be permanent redirection.



Note: clear browser cache then test






share|improve this answer






























    0














    For your RedirectMatch, you may use:



    RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?


    For your RewriteRule section, you may use:



    RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
    RewriteCond %QUERY_STRING id=([0-9]+) [NC]
    RewriteRule (.*) /thank-you [R=302,L,QSD]





    share|improve this answer

























      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%2f55285233%2fhtaccess-redirects-arent-respecting-my-regex%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









      0














      First , no need to RewriteEngine On with mod_alias which is RedirectMatch at your rules use it with mod_rewrite , the second rules .



      Try this :



      RewriteEngine On
      RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
      RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]


      I use ^id=([0-9]+)$ to restrict query string for a one that start with id and end with numerical value.



      I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/ becasue you could match against URI in RewriteRule as well.



      If this rules wrok , change [R=302,L] to [R=301,L] to be permanent redirection.



      Note: clear browser cache then test






      share|improve this answer



























        0














        First , no need to RewriteEngine On with mod_alias which is RedirectMatch at your rules use it with mod_rewrite , the second rules .



        Try this :



        RewriteEngine On
        RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
        RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]


        I use ^id=([0-9]+)$ to restrict query string for a one that start with id and end with numerical value.



        I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/ becasue you could match against URI in RewriteRule as well.



        If this rules wrok , change [R=302,L] to [R=301,L] to be permanent redirection.



        Note: clear browser cache then test






        share|improve this answer

























          0












          0








          0







          First , no need to RewriteEngine On with mod_alias which is RedirectMatch at your rules use it with mod_rewrite , the second rules .



          Try this :



          RewriteEngine On
          RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
          RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]


          I use ^id=([0-9]+)$ to restrict query string for a one that start with id and end with numerical value.



          I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/ becasue you could match against URI in RewriteRule as well.



          If this rules wrok , change [R=302,L] to [R=301,L] to be permanent redirection.



          Note: clear browser cache then test






          share|improve this answer













          First , no need to RewriteEngine On with mod_alias which is RedirectMatch at your rules use it with mod_rewrite , the second rules .



          Try this :



          RewriteEngine On
          RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
          RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]


          I use ^id=([0-9]+)$ to restrict query string for a one that start with id and end with numerical value.



          I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/ becasue you could match against URI in RewriteRule as well.



          If this rules wrok , change [R=302,L] to [R=301,L] to be permanent redirection.



          Note: clear browser cache then test







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 21 at 20:07









          Mohammed ElhagMohammed Elhag

          3,9261516




          3,9261516























              0














              For your RedirectMatch, you may use:



              RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?


              For your RewriteRule section, you may use:



              RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
              RewriteCond %QUERY_STRING id=([0-9]+) [NC]
              RewriteRule (.*) /thank-you [R=302,L,QSD]





              share|improve this answer





























                0














                For your RedirectMatch, you may use:



                RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?


                For your RewriteRule section, you may use:



                RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
                RewriteCond %QUERY_STRING id=([0-9]+) [NC]
                RewriteRule (.*) /thank-you [R=302,L,QSD]





                share|improve this answer



























                  0












                  0








                  0







                  For your RedirectMatch, you may use:



                  RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?


                  For your RewriteRule section, you may use:



                  RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
                  RewriteCond %QUERY_STRING id=([0-9]+) [NC]
                  RewriteRule (.*) /thank-you [R=302,L,QSD]





                  share|improve this answer















                  For your RedirectMatch, you may use:



                  RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?


                  For your RewriteRule section, you may use:



                  RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
                  RewriteCond %QUERY_STRING id=([0-9]+) [NC]
                  RewriteRule (.*) /thank-you [R=302,L,QSD]






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 21 at 20:30

























                  answered Mar 21 at 19:14









                  AdminOfThingsAdminOfThings

                  1,5951212




                  1,5951212



























                      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%2f55285233%2fhtaccess-redirects-arent-respecting-my-regex%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

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현