Smart search - set searchtext value to Lowercase in Url

Tracey Penberthy asked on October 25, 2017 13:12

Hi

Is there a way to force the smart search dialog web part to put the search text to lowercase in the Url?

e.g. searchtext=Hello+World to searchtext=hello+world

In Settings > Urls and SEO > Redirect invalid case URLs to their correct versions is set to "Redirect all requests to lower case urls" but this doesn't seem to effect the smart search requests.

The reason for wanting to do this is that we are getting duplicate records in Google Analytics as it tracks pages separately depending on case used.

Many Thanks Tracey

Recent Answers


David te Kloese answered on October 25, 2017 13:29

Well you could do a few things:

  • update the webpart code to redirect to lower case

  • create IIS-URL Rewrite to target only search queries..

But perhaps you could also look into adjusting your GA to combine them using a filter. Haven't tested this but found this online:

Google Analytics >> Admin >> Account >> Property >> View >>Filters >> New Filter.

Next select: Create Filter >> Filter Name “Force Lowercase” >> Filter Type “Custom” select “Lowercase” >> Filter Field “Request URI” >> Hit “Save”
1 votesVote for this answer Mark as a Correct answer

Matt Nield answered on October 25, 2017 13:35 (last edited on October 25, 2017 13:37)

Hi Tracey, there is perhaps an alternative approach of using REL canonical in your pages so that all of the search results pages are treated as one. In your example having <link rel="canonical" href="/search.aspx"> should (unless google have changed everything. again.) start to reduce the duplicate records in GA. This has some reasonable insight: Specify your canonical

To change the case anyway, you could modify the CMSWebParts_SmartSearch_SearchBox.Search method (found in CMSWebParts\SmartSearch) to convert the search term to lower case so that:

url = URLHelper.UpdateParameterInUrl(url, "searchtext", HttpUtility.UrlEncode(txtWord.Text));

becomes

url = URLHelper.UpdateParameterInUrl(url, "searchtext", HttpUtility.UrlEncode(txtWord.Text.ToLowerInvariant()));
2 votesVote for this answer Mark as a Correct answer

Tracey Penberthy answered on October 25, 2017 16:01

Thanks David and Matt

Great suggestions, really helpful.

I am going to go with the UpdateParameterInUrl method because we have already cloned the Search Dialog web control to provide some custom markup so this would be the easier solution for us to implement.

0 votesVote for this answer Mark as a Correct answer

Matt Nield answered on October 25, 2017 16:06

Glad to help :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.