locked
Force SharePoint 2013 to use a 301 Redirect instead of a 302 Redirect by default. RRS feed

  • Question


  • Does anyone know of a way to configure SharePoint so that when it redirects a user from a root site collection, say https://www.foo.com to https://www.foo.com/Pages/default.aspx it will do so with a 301 (Permanent) versus a 302 (Temporary) redirect? The default in SharePoint is 302 but we really need to do this as a 301.

    We have a specific need for our root-site collections to return the 301 redirect instead of the 302 because of some services we are using with Google. For some reason the 302 redirect causes issues.

    We just upgraded our SP2010 farm to SP2013 and we had a redirect rule in place in the SP2010 farm using IIS Rewrite Module and it worked great but in SP2013 using the same redirect rule causes our SharePoint Search crawl to halt and we can't get any crawling on our site collections. Once I comment out the offending rewrite rule our search crawler works as expected.

    Thanks.

    Wednesday, March 30, 2016 4:38 PM

Answers

  • Hi,

    In SharePoint 2013, I don’t suggest you change to 301.

    Crawl and other functionalities will be adversely affected in changed to 301. If you permanently redirect site to another URL, crawler will stop work. It’s by design in SP2013.

    301 is a Permanent Redirection while 302 is a temporary one. The difference between a 301 and a 302 is that a 301 status code means that a page has permanently moved to a new location, while a 302 status code means that a page has temporarily moved to a new location. The problem is SharePoint uses 302 redirects for its a?Redirect Pagea? layout. The whole issue about the 302 headers is that the redirected locations don't get crawled by search spiders which don't follow temporarily moved pages. While it's not really an issue for intranet environments it has major impact on indexing the content of Internet-facing web sites and making them searchable using a search engine. But replacing 302s with 301s will permanent cache those pages and hence affect routing in general. Hence we by default suggest you not change this redirection.

    Thanks,

    Dean Wang


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Victoria Xia Monday, April 11, 2016 1:44 AM
    • Marked as answer by Victoria Xia Monday, April 11, 2016 10:27 AM
    Friday, April 8, 2016 3:17 AM

All replies

  • Hi,

    You can try to manage the redirects within the web.config file.

    More detailed information for your reference:

    https://spmatt.wordpress.com/tag/301-redirect/

    You can use SPWebConfigModification to Update the Web.config in SharePoint 2013.

    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx?f=255&MSPPError=-2147217396

    Thanks,

    Dean Wang


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, March 31, 2016 7:54 AM
  • Dean, The link seems to talk about adding redirect rules programmatically.

    We are currently using the IIS Rewrite Module in both our old SP2010 farm and the new SP2013 farm. We have the following rule implemented in the old SP2010 farm and this works quite well:

            <rule name="Home Page Special Redirect" enabled="true" stopProcessing="true">
              <match url="^$" ignoreCase="true" />
              <conditions>
              </conditions>
              <action type="Redirect" url="{R:0}/pages/default.aspx" redirectType="Permanent"/>
            </rule>

    This rule also sits in the "configuration/system.webServer/rewrite/rules" path as mentioned in the article, and while it DOES work with SharePoint 2013 it causes the search crawler to fail.

    Initially, I thought this was a problem with the search service application in SP2013 in how it handles permanent redirects but it is not affected by other permanent redirect rules we have in place. There are about some 50+ redirect rules we have in place which were transferred over from our SP2010 environment and they all work as expected. The only impact is with the search crawl service. In our SP2010 environment we used the Fast Search service and had no problems with the above rule but for some reason the default SP2013 search service crawl does.


    • Edited by JM Estrada Thursday, March 31, 2016 2:49 PM
    Thursday, March 31, 2016 2:47 PM
  • Hi,

    How did you know that the crawl error was caused by the redirect 301?

    Can you provide the detailed error message about the failed search crawl?

    Thanks,

    Dean Wang


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, April 4, 2016 2:12 AM
  • This is the error that is being reported by the crawler and shows up in the crawl history:

    The URL was permanently moved. ( URL redirected to https://www.host.com/Pages/default.aspx; ; SearchID = D461464C-F111-4263-BB8C-78644856BCDC )

    As mentioned earlier, if I have the one rewrite rule included in our web.config file the crawler will hit all twelve of our site collections then halt on each one with the above message. This rule does not cause a problem in  SP2010 though and we've been using it for some time.

    I would like to know if there is a way to configure the Search crawler service to not halt and continue on. I've bot been able to find much information about this specific issue.

    Now, with that out of the way, I have worked around the problem by designating the one APP server we are using to run the search services from and am pointing that server to crawl the web application that is being hosted on itself for our site collections. Doing this, I can exclude the one rewrite rule and allow my search crawl to complete. I'm guessing this may just have to be the solution to this problem unless I can figure out a way to prevent the crawler from halting when it hits this one rule while crawling the web front-end servers.

    Tuesday, April 5, 2016 4:13 PM
  • Hi,

    In SharePoint 2013, I don’t suggest you change to 301.

    Crawl and other functionalities will be adversely affected in changed to 301. If you permanently redirect site to another URL, crawler will stop work. It’s by design in SP2013.

    301 is a Permanent Redirection while 302 is a temporary one. The difference between a 301 and a 302 is that a 301 status code means that a page has permanently moved to a new location, while a 302 status code means that a page has temporarily moved to a new location. The problem is SharePoint uses 302 redirects for its a?Redirect Pagea? layout. The whole issue about the 302 headers is that the redirected locations don't get crawled by search spiders which don't follow temporarily moved pages. While it's not really an issue for intranet environments it has major impact on indexing the content of Internet-facing web sites and making them searchable using a search engine. But replacing 302s with 301s will permanent cache those pages and hence affect routing in general. Hence we by default suggest you not change this redirection.

    Thanks,

    Dean Wang


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Victoria Xia Monday, April 11, 2016 1:44 AM
    • Marked as answer by Victoria Xia Monday, April 11, 2016 10:27 AM
    Friday, April 8, 2016 3:17 AM
  • Dean,

    I understand the differences between a 301 and a 302, however we are using some services that Google requires a 301 redirect for. The reason we must use a 301 redirect is due to SEO value.

    As I mentioned before, I worked around this by configuring our web front-end servers so that they are using the redirect rule and returning a 301 redirect. We have a vendor that we are working with who manages the design and custom coding of our site content, and they are requiring us to use the 301 redirect for the services they rely on from Google.

    With our web front-end servers configured to use 301, I have had to configure our application server that actually hosts the search service application so that the web application for our site is accessible on the server itself, and it is in this web-application that I have omitted the rule so that our search engine will crawl without failing.

    Our vendor wanted me to find a permanent solution so that we are crawling the web front-end servers but it sounds to me like that will not be possible, based on what your statement that SharePoint is designed to halt on a 301 redirect.

    Do you by chance have a link to an official document from Microsoft that states this? I would like to present this to our vendor so they are aware of this also.

    Monday, April 11, 2016 2:57 PM