Using IIS URL Rewrite to force all lower-case URLs breaks Sitefinity backend
I followed the instructions on SF documentation for Using URL Rewrite for SEO. The rule to force all URLs to lower-case DOES NOT WORK correctly. The backend breaks. Trying to edit any page (under PAGES in backend) results in a nasty client-side (web browser) error when trying to publish the page. Something about character set not being equal to published character encoding, blah blah blah.
This is the rule I added, per Sitefinity documentation:
<
rule
name
=
"Convert URLs to lower case"
enabled
=
"true"
stopProcessing
=
"true"
>
<
match
url
=
"[A-Z]"
ignoreCase
=
"false"
/>
<
conditions
>
<
add
input
=
"REQUEST_URI"
pattern
=
"^/sitefinity/"
negate
=
"true"
/>
</
conditions
>
<
action
type
=
"Redirect"
url
=
"ToLower:URL"
redirectType
=
"Permanent"
/>
</
rule
>
After I commented-out the entire rule, my webpages were able to be published correctly. I believe the error stems from the fact that, once a page is in edit mode, the URL is something like
http://mysite.com/pagename/action/edit
It seems that the "action/edit" must not be lower-case (really, Telerik, really?). The rule does not account for those exceptions (although it does try to make an exception for "/sitefinity/" but that's not good enough).
I can imagine that can be fixed by adding some additional exceptions to the URL Rewrite rule, but I'm not an expert on those, so I will not attempt to do it myself. Plus, this was in SF documentation, so if you ask me, this is a bug and a failure on Telerik's part to fully test something before releasing instructions.
So, I'm asking Telerik to please update your documentation on this, and let us know how to PROPERLY add a rewrite rule for forcing lower-case URLs while NOT breaking your backend. I understand it is not your job to teach us how to use IIS URL Rewrite, but it IS your job to tell us what can and can't be accessed by lower-case URL in backend.
There's a big laundry list of SEO url things that need documenting\fixing...it'd be nice if it just worked a bit nicer out of the box :/
Anyway, this is what I use...always a WIP though.
<
rules
>
<
clear
/>
<
rule
name
=
"LowerCaseRule1"
stopProcessing
=
"true"
>
<
match
url
=
"^(Sitefinity/)"
ignoreCase
=
"true"
negate
=
"true"
/>
<
conditions
logicalGrouping
=
"MatchAll"
trackAllCaptures
=
"false"
>
<
add
input
=
"URL"
pattern
=
"[A-Z]"
ignoreCase
=
"false"
/>
<
add
input
=
"URL"
pattern
=
"\.axd"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"\.xamlx"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"\.ashx"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"\.asmx"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"\.xap"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"bundles"
negate
=
"true"
/>
<
add
input
=
"REQUEST_FILENAME"
pattern
=
"SFRes"
negate
=
"true"
/>
</
conditions
>
<
action
type
=
"Redirect"
url
=
"ToLower:URL"
redirectType
=
"Permanent"
/>
</
rule
>
<
rule
name
=
"RemoveTrailingSlashRule1"
stopProcessing
=
"true"
>
<
match
url
=
"(.*)/$"
/>
<
conditions
logicalGrouping
=
"MatchAll"
trackAllCaptures
=
"false"
>
<
add
input
=
"REQUEST_FILENAME"
matchType
=
"IsDirectory"
negate
=
"true"
/>
<
add
input
=
"REQUEST_FILENAME"
matchType
=
"IsFile"
negate
=
"true"
/>
<
add
input
=
"REQUEST_FILENAME"
pattern
=
"(.*?)\.svc$"
negate
=
"true"
/>
<
add
input
=
"REQUEST_FILENAME"
pattern
=
"bundles"
negate
=
"true"
/>
</
conditions
>
<
action
type
=
"Redirect"
url
=
"R:1"
/>
</
rule
>
</
rules
>
Thanks, Steve! I think this works, at least for the problems I was seeing before. I appreciate your input.
I just wish Telerik was more proactive and thorough with their documentation. Probably my biggest gripe with them, for the last 5 years that I've been their customer. :-(
On the subject of rewrite rules, I've just put in place a rule to redirect requests to domain root to a specific home page (in order to enforce consistent SEO and Google Analytics reporting for the home page). I want to make sure this doesn't break Sitefinity like the other one did. Any problems with this:
<
rule
name
=
"Home Page Redirect"
enabled
=
"true"
stopProcessing
=
"true"
>
<
match
url
=
"^$"
/>
<
action
type
=
"Redirect"
url
=
"home"
redirectType
=
"Permanent"
/>
</
rule
>
The idea is to redirect something like http://www.mysite.com to www.mysite.com/home.
The other option was to redirect the other way around (when www.mysite.com/home is requested redirect to www.mysite.com but I was getting inconsistent behavior across browsers--IE was leaving a trailing slash, even though I have a rule for that, while FF was doing it without trailing slash). So I decided it might be easier to redirect to "home" instead.
Patrick Dunn has posted some great tricks in his blog reguarding SEO in sitefinity:
patrickdunn.me/.../seo-in-sitefinity-1-different-url-casings
patrickdunn.me/.../seo-in-sitefinity-2-avoiding-duplicate-homepage-urls
patrickdunn.me/.../seo-in-sitefinity-3-remove-www-from-url
patrickdunn.me/.../seo-in-sitefinity-4-remove-default-aspx-from-all-requests
The URL rewrites seem to break the new Google Analytics module in 6.3. Has anyone figured out a work-around yet?
These are the rules I'm using:
www.sitefinity.com/.../using-url-rewrite-for-seo
If anyone else runs into this, you need to add a pattern for "RestApi" to the LoweCaseRule
<
rule
name
=
"LowerCaseRule1"
stopProcessing
=
"true"
>
<
match
url
=
"^(Sitefinity/)"
ignoreCase
=
"true"
negate
=
"true"
/>
<
conditions
logicalGrouping
=
"MatchAll"
trackAllCaptures
=
"false"
>
<
add
input
=
"URL"
pattern
=
"[A-Z]"
ignoreCase
=
"false"
/>
<
add
input
=
"URL"
pattern
=
"\.axd"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"\.xamlx"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"\.ashx"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"\.asmx"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"\.xap"
negate
=
"true"
/>
<
add
input
=
"URL"
pattern
=
"bundles"
negate
=
"true"
/>
<
add
input
=
"REQUEST_FILENAME"
pattern
=
"SFRes"
negate
=
"true"
/>
<
add
input
=
"REQUEST_FILENAME"
pattern
=
"RestApi"
negate
=
"true"
/>
</
conditions
>
<
action
type
=
"Redirect"
url
=
"ToLower:URL"
redirectType
=
"Permanent"
/>
</
rule
>
Thanks Steve this was a huge help.
Has anything changed since this post in terms of what Sitefinity does out the box, or perhaps something you now do differently?