Tag Archives: SEO

sc_itemid Query String – Having a detrimental effect on the SEO

If the sc_itemid query string has a valid sitecore item ID (and or sitecore path), sitecore ignores the URL path and sets the current item to the specified item.

This is generally used by the sitecore client tools i.e., preview, experience editor, debugging, etc. to specify the current item.

Unfortunately, one customer identified that the use of sc_itemid, was having a detrimental effect on the SEO for their websites, but why was sc_itemid present on their public available websites?

I believed the correct solution was to identify why sc_itemid was present in the URL and correct the issue.

Unfortunately, after identifying several issues relating to editor’s content, legacy system and legacy code, the customer informed me that they could not be resolved/fixed and asked me to find an alternative solution.


If it is not a sitecore client request and sc_itemid is present make a permanent redirect, following the these rules:

  • If the sc_itemid has a valid item id or path, make a permanent redirect to canonical URL for the item.
  • If the sc_itemid does not have a valid item id or path, strip the sc_itemid query string and make a permanent redirect to that URL.

Step 1 – httpRequestBegin Pipeline Processor

Introduce a pipeline processor to check URL’s and add it to the httpRequestBegin pipeline just before the LayoutResolver processor.

Define which site’s should be ignored, for example the sitecore client typically uses the shell site context.

Define which URL paths should be ignored, for example URL’s starting with /sitecore are usually for the sitecore client, see the config below for more typical examples.

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <processor type="Feature.ErrorHandling.Infrastructure.Pipelines.QueryStringPermanentlyRedirectHttpRequestProcessor, Feature.ErrorHandling"
				           patch:before="processor[@type='Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel']"
          <IgnoreSites hint="list:AddIgnoreSite">
            <!--list of all the sites to ignore-->
          <IgnorePaths hint="list:AddIgnorePath">
            <!--list of all the sites to ignore-->

Step 2 – Which Requests/URL’s to ignore

The most important part of the any pipeline processors is to ensure that it identifies requests to ignore and exits as soon as possible, as all request go through the httpRequestBegin pipeline.

Therefore the QueryStringPermanentlyRedirectHttpRequestProcessor must check the following and exit if one of the conditions is true.

  • Local path is null
  • Http Context is null
  • The pipeline is aborted
  • The query string sc_itemid is not present
  • The Site context is in the Ignore Sites list (see configuration above)
  • The URL path starts with the path in the ignore paths list (see configuration above)
    • Context.PageMode.IsNormal is not true i.e. It is a sitecore client request – editing, preview, experience, debugging, etc.
  • Is a request for a physical file

Step 3 – Abort the Pipeline & Permanent Redirect

The last step is simple, make the permanent redirect depending on the following logic:

  • If sc_itemid identifies a valid item, get the canonical URL and redirect.
  • If sc_itemid does not identifies a valid item, remove the sc_itemid querystring and redirect to the URL.

Remember to abort the pipeline first before redirecting and catch the ThreadAbortException, see the code below

            catch (ThreadAbortException ex)
                // do nothing, as this is caused by the redirect

Hope this helps, Alan