Regex in Web.config Rewrite Rules for partial lowercase URL
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
add a comment |
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
I get aERR_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 changeignoreCase="false"
toignoreCase="true"
, then just useurl="(.*)"
andurl="{ToLower:{R:1}}"
.
– Wiktor Stribiżew
Nov 19 '18 at 9:20
Wiktor that causes the sameERR_TOO_MANY_REDIRECTS
error
– Serj Sagan
Nov 19 '18 at 9:48
add a comment |
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
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
c# asp.net regex url-rewriting web-config
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 aERR_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 changeignoreCase="false"
toignoreCase="true"
, then just useurl="(.*)"
andurl="{ToLower:{R:1}}"
.
– Wiktor Stribiżew
Nov 19 '18 at 9:20
Wiktor that causes the sameERR_TOO_MANY_REDIRECTS
error
– Serj Sagan
Nov 19 '18 at 9:48
add a comment |
I get aERR_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 changeignoreCase="false"
toignoreCase="true"
, then just useurl="(.*)"
andurl="{ToLower:{R:1}}"
.
– Wiktor Stribiżew
Nov 19 '18 at 9:20
Wiktor that causes the sameERR_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
add a comment |
1 Answer
1
active
oldest
votes
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>
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 19 '18 at 9:48
Serj SaganSerj Sagan
15.4k10102121
15.4k10102121
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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"
toignoreCase="true"
, then just useurl="(.*)"
andurl="{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