Implementing Sitecore Multisite Robots.txt Files

How to implement, in order to have different robots.txt files for each website hosted on the same Sitecore solution. I want to read dynamically robots.txt from sitecore elements.

+4
source share
4 answers

you need to follow these steps:

1) Create and implement your own universal (.ashx) handler.

2) In the web.config file, add the following line to the section

3) Go to the section and add here

4) In the home element, you will have the Robots field (the memo field or the multi-line field, not the richText field). Your custom common handler will look like this:

 public class Robots : IHttpHandler
{

    public virtual void ProcessRequest(HttpContext context)
    {
        private string defaultRobots = "your default robots.txt content ";

        string robotsTxt = defaultRobots;

        if ((Sitecore.Context.Site == null) || (Sitecore.Context.Database == null))
        {
            robotsTxt = defaultRobots;
        }
        Item itmHomeNode = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath);
        if (itmHomeNode != null)
        {
            if ((itmHomeNode.Fields["Robots"] != null) && (itmHomeNode.Fields["Robots"].Value != ""))
            {
                robotsTxt = itmHomeNode.Fields["Robots"].Value;
            }
        }

        context.Response.ContentType = "text/plain";
        context.Response.Write(robotsTxt);

    }
+7
source

, , robots.txt

, IHTTPHandler, . XML .

context.Response.ContentType = "text/plain";
context.Response.Output.Write({XML DATA});

.

  <handler trigger="~/Handlers/" handler="robots.txt"/>

  <add name="{Name}" path="robots.txt" verb="*" type="{Assembly Name and Type}" />
+1

, Sitecore , , . aboce , .

, Sitecore.Context HttpRequestProcessor Sitecore, robots.txt -: http://darjimaulik.wordpress.com/2013/03/06/how-to-create-handler-in-sitecore/

+1

You can link to this blog post for a step-by-step explanation of how to do this using the custom HttpRequestProcessor and custom robotic settings template: http://nsgocev.wordpress.com/2014/07/30/handling-sitecore-multi-site- instance-robots-txt /

0
source

All Articles