This article is specific to Sitecore but can be helpful for other ASP.NET-based applications as well.
1. URL with Uppercase / Capital Letters:
It is recommended that the URL should be always in lowercase / small letters looking from an SEO perspective. Sometimes if the URL with a capital letter comes in through the request. We can detect it in URL Rewrite and redirect it by converting it to lowercase format. Eg.
URL with Lowercase or small letters (non-SEO friendly):
https://mysite.local/products/VEHICLES/Wheel Based Arrow/Some Wheel Lok
URL with Uppercase or Capital letters (SEO friendly):
https://mysite.local/products/vehicles/wheel-based-arrow/some-wheel-lok
Here, we have replaced the “ ” (blank space) from the URL with “-” and redirected the request to the newly formed URL.
2. URL with “ ” space in it or URL without Slug:
The URL request without any slug used in it or blank space within the URL is not considered SEO friendly. In such scenarios as well we can use URL Rewrite to redirect by replacing blank spaces with slug. Eg.
URL without Slug (non-SEO friendly):
https://mysite.local/products/vehicles/wheel based arrow/some wheel lok
URL with Slug (SEO friendly):
https://mysite.local/products/vehicles/wheel-based-arrow/some-wheel-lok
Here, we have replaced the “ ” (blank space) from the URL with “-” and redirected the request to the newly formed URL.
Let's see how to achieve it !!!
Changes in Rewrite rules
For Non Sitecore Applications:
1. Convert uppercase URLs to lowercase URLs:
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
Rule 1 in Rewriterules.config:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <rule name="LowerCaseRule1" enabled="true" stopProcessing="true"> <match url="[A-Z]" ignoreCase="false" /> <action type="Redirect" url="{ToLower:{URL}}" /> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern=".*Captcha.*" negate="true" /> <add input="{URL}" pattern=".*media.*" negate="true" /> <add input="{URL}" pattern=".*services\/resources.*" negate="true" /> <add input="{URL}" pattern=".*content.*" negate="true" /> <add input="{URL}" pattern="^/sitecore" negate="true" /> <add input="{URL}" pattern="^/sitecore%20modules" negate="true" /> <add input="{URL}" pattern="^/sitecore modules" negate="true" /> <add input="{URL}" pattern="^/temp" negate="true" /> <add input="{URL}" pattern="^/ScriptResource" negate="true" /> <add input="{URL}" pattern="^/WebResource" negate="true" /> <add input="{URL}" pattern="\.axd" negate="true" /> <add input="{URL}" pattern="\.asmx" negate="true" /> <add input="{URL}" pattern="\.svc" negate="true" /> <add input="{URL}" pattern="^/layouts/system" negate="true" /> <add input="{HTTP_URL}" pattern="\?.*sc_mode" negate="true" /> <add input="{URL}" pattern="\/-\/speak" negate="true" /> <add input="{URL}" pattern="^/api" negate="true" /> <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" /> </conditions> </rule> |
2. Replace blank space from URLs with dash/hyphen (-):
Rule 2 in Rewriterules.config:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <rule name="BlankSpaceRule" enabled="true" stopProcessing="true"> <match url="(.*) (.*)" ignoreCase="true" /> <action type="Redirect" url="{R:1}-{R:2}" /> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern=".*Captcha.*" negate="true" /> <add input="{URL}" pattern=".*media.*" negate="true" /> <add input="{URL}" pattern=".*services\/resources.*" negate="true" /> <add input="{URL}" pattern=".*content.*" negate="true" /> <add input="{URL}" pattern="^/sitecore" negate="true" /> <add input="{URL}" pattern="^/sitecore%20modules" negate="true" /> <add input="{URL}" pattern="^/sitecore modules" negate="true" /> <add input="{URL}" pattern="^/temp" negate="true" /> <add input="{URL}" pattern="^/ScriptResource" negate="true" /> <add input="{URL}" pattern="^/WebResource" negate="true" /> <add input="{URL}" pattern="\.axd" negate="true" /> <add input="{URL}" pattern="\.asmx" negate="true" /> <add input="{URL}" pattern="\.svc" negate="true" /> <add input="{URL}" pattern="^/layouts/system" negate="true" /> <add input="{HTTP_URL}" pattern="\?.*sc_mode" negate="true" /> <add input="{URL}" pattern="\/-\/speak" negate="true" /> <add input="{URL}" pattern="^/api" negate="true" /> <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" /> </conditions> </rule> |
0 Comments