Regex in Web.config Rewrite Rules for partial lowercase URL












1















For SEO I want my URLs to be consistent but I don't want that to affect any query parameters. So for example:
These URLs:




  • https://www.eXample.com/blog/article/

  • https://www.example.com/Blog/article/

  • https://www.example.com/blog/aRtiCle/

  • https://www.eXamPle.com/bLoG/aRtiClE/


should all become:




  • https://www.example.com/blog/article/


However this one:




  • https://www.eXamPle.com/bLoG/aRtiClE/?q=aRtGHg


should be:




  • https://www.example.com/blog/article/?q=aRtGHg


I kind of have something that works sometimes with this:



    <rule name="LowerCaseRule" stopProcessing="true">
<match url="([A-Z]+)(.*)" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}{R:2}}" redirectType="Permanent" />
</rule>









share|improve this question

























  • I get a ERR_TOO_MANY_REDIRECTS error with that

    – Serj Sagan
    Nov 19 '18 at 7:58











  • I don't have time to test at the moment, but you can probably do something with conditions.

    – John
    Nov 19 '18 at 8:09













  • It seems you should change ignoreCase="false" to ignoreCase="true", then just use url="(.*)" and url="{ToLower:{R:1}}".

    – Wiktor Stribiżew
    Nov 19 '18 at 9:20











  • Wiktor that causes the same ERR_TOO_MANY_REDIRECTS error

    – Serj Sagan
    Nov 19 '18 at 9:48
















1















For SEO I want my URLs to be consistent but I don't want that to affect any query parameters. So for example:
These URLs:




  • https://www.eXample.com/blog/article/

  • https://www.example.com/Blog/article/

  • https://www.example.com/blog/aRtiCle/

  • https://www.eXamPle.com/bLoG/aRtiClE/


should all become:




  • https://www.example.com/blog/article/


However this one:




  • https://www.eXamPle.com/bLoG/aRtiClE/?q=aRtGHg


should be:




  • https://www.example.com/blog/article/?q=aRtGHg


I kind of have something that works sometimes with this:



    <rule name="LowerCaseRule" stopProcessing="true">
<match url="([A-Z]+)(.*)" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}{R:2}}" redirectType="Permanent" />
</rule>









share|improve this question

























  • I get a ERR_TOO_MANY_REDIRECTS error with that

    – Serj Sagan
    Nov 19 '18 at 7:58











  • I don't have time to test at the moment, but you can probably do something with conditions.

    – John
    Nov 19 '18 at 8:09













  • It seems you should change ignoreCase="false" to ignoreCase="true", then just use url="(.*)" and url="{ToLower:{R:1}}".

    – Wiktor Stribiżew
    Nov 19 '18 at 9:20











  • Wiktor that causes the same ERR_TOO_MANY_REDIRECTS error

    – Serj Sagan
    Nov 19 '18 at 9:48














1












1








1








For SEO I want my URLs to be consistent but I don't want that to affect any query parameters. So for example:
These URLs:




  • https://www.eXample.com/blog/article/

  • https://www.example.com/Blog/article/

  • https://www.example.com/blog/aRtiCle/

  • https://www.eXamPle.com/bLoG/aRtiClE/


should all become:




  • https://www.example.com/blog/article/


However this one:




  • https://www.eXamPle.com/bLoG/aRtiClE/?q=aRtGHg


should be:




  • https://www.example.com/blog/article/?q=aRtGHg


I kind of have something that works sometimes with this:



    <rule name="LowerCaseRule" stopProcessing="true">
<match url="([A-Z]+)(.*)" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}{R:2}}" redirectType="Permanent" />
</rule>









share|improve this question
















For SEO I want my URLs to be consistent but I don't want that to affect any query parameters. So for example:
These URLs:




  • https://www.eXample.com/blog/article/

  • https://www.example.com/Blog/article/

  • https://www.example.com/blog/aRtiCle/

  • https://www.eXamPle.com/bLoG/aRtiClE/


should all become:




  • https://www.example.com/blog/article/


However this one:




  • https://www.eXamPle.com/bLoG/aRtiClE/?q=aRtGHg


should be:




  • https://www.example.com/blog/article/?q=aRtGHg


I kind of have something that works sometimes with this:



    <rule name="LowerCaseRule" stopProcessing="true">
<match url="([A-Z]+)(.*)" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}{R:2}}" redirectType="Permanent" />
</rule>






c# asp.net regex url-rewriting web-config






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 7:48







Serj Sagan

















asked Nov 19 '18 at 7:42









Serj SaganSerj Sagan

15.4k10102121




15.4k10102121













  • I get a ERR_TOO_MANY_REDIRECTS error with that

    – Serj Sagan
    Nov 19 '18 at 7:58











  • I don't have time to test at the moment, but you can probably do something with conditions.

    – John
    Nov 19 '18 at 8:09













  • It seems you should change ignoreCase="false" to ignoreCase="true", then just use url="(.*)" and url="{ToLower:{R:1}}".

    – Wiktor Stribiżew
    Nov 19 '18 at 9:20











  • Wiktor that causes the same ERR_TOO_MANY_REDIRECTS error

    – Serj Sagan
    Nov 19 '18 at 9:48



















  • I get a ERR_TOO_MANY_REDIRECTS error with that

    – Serj Sagan
    Nov 19 '18 at 7:58











  • I don't have time to test at the moment, but you can probably do something with conditions.

    – John
    Nov 19 '18 at 8:09













  • It seems you should change ignoreCase="false" to ignoreCase="true", then just use url="(.*)" and url="{ToLower:{R:1}}".

    – Wiktor Stribiżew
    Nov 19 '18 at 9:20











  • Wiktor that causes the same ERR_TOO_MANY_REDIRECTS error

    – Serj Sagan
    Nov 19 '18 at 9:48

















I get a ERR_TOO_MANY_REDIRECTS error with that

– Serj Sagan
Nov 19 '18 at 7:58





I get a ERR_TOO_MANY_REDIRECTS error with that

– Serj Sagan
Nov 19 '18 at 7:58













I don't have time to test at the moment, but you can probably do something with conditions.

– John
Nov 19 '18 at 8:09







I don't have time to test at the moment, but you can probably do something with conditions.

– John
Nov 19 '18 at 8:09















It seems you should change ignoreCase="false" to ignoreCase="true", then just use url="(.*)" and url="{ToLower:{R:1}}".

– Wiktor Stribiżew
Nov 19 '18 at 9:20





It seems you should change ignoreCase="false" to ignoreCase="true", then just use url="(.*)" and url="{ToLower:{R:1}}".

– Wiktor Stribiżew
Nov 19 '18 at 9:20













Wiktor that causes the same ERR_TOO_MANY_REDIRECTS error

– Serj Sagan
Nov 19 '18 at 9:48





Wiktor that causes the same ERR_TOO_MANY_REDIRECTS error

– Serj Sagan
Nov 19 '18 at 9:48












1 Answer
1






active

oldest

votes


















1














Thanks to the helpful comments by John,I got it to work like this:



    <rule name="LowerCaseRule" stopProcessing="true">
<match url="^(.*?)(?.*|$)" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_NAME}" pattern="[A-Z]" ignoreCase="false" />
<add input="{PATH_INFO}" pattern="[A-Z]" ignoreCase="false" />
</conditions>
<action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
</rule>





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%2f53370263%2fregex-in-web-config-rewrite-rules-for-partial-lowercase-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









    1














    Thanks to the helpful comments by John,I got it to work like this:



        <rule name="LowerCaseRule" stopProcessing="true">
    <match url="^(.*?)(?.*|$)" ignoreCase="false" />
    <conditions logicalGrouping="MatchAny">
    <add input="{SERVER_NAME}" pattern="[A-Z]" ignoreCase="false" />
    <add input="{PATH_INFO}" pattern="[A-Z]" ignoreCase="false" />
    </conditions>
    <action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
    </rule>





    share|improve this answer




























      1














      Thanks to the helpful comments by John,I got it to work like this:



          <rule name="LowerCaseRule" stopProcessing="true">
      <match url="^(.*?)(?.*|$)" ignoreCase="false" />
      <conditions logicalGrouping="MatchAny">
      <add input="{SERVER_NAME}" pattern="[A-Z]" ignoreCase="false" />
      <add input="{PATH_INFO}" pattern="[A-Z]" ignoreCase="false" />
      </conditions>
      <action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
      </rule>





      share|improve this answer


























        1












        1








        1







        Thanks to the helpful comments by John,I got it to work like this:



            <rule name="LowerCaseRule" stopProcessing="true">
        <match url="^(.*?)(?.*|$)" ignoreCase="false" />
        <conditions logicalGrouping="MatchAny">
        <add input="{SERVER_NAME}" pattern="[A-Z]" ignoreCase="false" />
        <add input="{PATH_INFO}" pattern="[A-Z]" ignoreCase="false" />
        </conditions>
        <action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
        </rule>





        share|improve this answer













        Thanks to the helpful comments by John,I got it to work like this:



            <rule name="LowerCaseRule" stopProcessing="true">
        <match url="^(.*?)(?.*|$)" ignoreCase="false" />
        <conditions logicalGrouping="MatchAny">
        <add input="{SERVER_NAME}" pattern="[A-Z]" ignoreCase="false" />
        <add input="{PATH_INFO}" pattern="[A-Z]" ignoreCase="false" />
        </conditions>
        <action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
        </rule>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 9:48









        Serj SaganSerj Sagan

        15.4k10102121




        15.4k10102121






























            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%2f53370263%2fregex-in-web-config-rewrite-rules-for-partial-lowercase-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

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)