magento2 – Sitemap and Product URLS to include a specific parent category in URL – Magento 2

I would like to use the “Use Categories Path for Product URLs” feature within Magento 2 however default to it. Not only that but in the case a product belongs to multiple categories be able to set the default path to include a “Master” category.

By default the sitemap seems to generate basic urls like domain.com/product.html. And even when “Use Categories Path for Product URLs” is set to enabled the products are accessible from other urls. I want to achieve domain.com/master-category/product.html as the only route to that product if possible.

Not sure the best route to achieve this weather it be a module that creates redirects based on master categories and generates URLS redirects accordingly and then similarly mods the sitemap generation to include these URLS or if there is an easier route e.g default settings or recommended module?

How do I limit use of Simple XML Sitemap to certain roles?

For my Page content type, I want nodes created by administrators to be in my Simple XML Sitemap, but I want to exclude nodes created by non-admin users.

Administrators have permission to administer Simple XML Sitemap, and regular users do not.

On the Page content type settings, I have checked the box to index nodes of type Page by default. (You must enable indexing by default in order to get the Simple XML Sitemap settings widget on the node edit screen.)

I tried to change the settings in hook_form_alter(), but it doesn’t work because non-admin users do not ever see the Simple Sitemap widget (it is not attached to the form if the user does not have admin permission for Simple XML Sitemap).

So I’m stuck:

  • I have to enable indexing by default on the node edit page to get the widget to appear.
  • Non-admin users do not have access to the widget, so I cannot change the value for non-admin users with hook_form_alter() (I have to accept the default).

How do I resolve this paradox?

c# – Small sitemap checker .aspx file

I wrote a small sitemap-checker.aspx, the goal of this code is to find the pages, that respond with the codes other than 200. I’ve only put the C# part here for the review:

    void Start_Click(object sender, EventArgs e)
    {
        CheckUrls(UrlTextBox.Text);
    }

    private void CheckUrls(string url)
    {
        try
        {
            var xmlDoc = LoadXml(url);
            var urlNodes = xmlDoc.GetElementsByTagName("url");
            var numberOfNodes = urlNodes.Count;
            var index = 0;
            
            Log("### Total nodes: " + numberOfNodes+ "<br>");
            Log("Here is the list of URLs, with the status code other than 200: <br>");
            foreach (XmlNode urlNode in urlNodes)
            {
                CheckUrlNode(urlNode, xmlDoc);
                index++;

                if(index % 10 == 0)
                {
                    Log("<span style='color:red'>" + index + " nodes of " + numberOfNodes + " are finished, please wait...</span>");
                }
            };
            Log("### Sitemap check finished. Please analyze the reported urls<br><br>");
        }
        catch (Exception e)
        {
            Log("Some problems were encountered while checking the sitemap<br>");
            Log(e.Message + "<br>");
            Log(e.StackTrace + "<br>");
        }
    }

    private XmlDocument LoadXml(string url)
    {
        var m_strFilePath = url;
        string xmlStr;
        using (var wc = new WebClient())
        {
            xmlStr = wc.DownloadString(m_strFilePath);
        }
        var xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xmlStr);
        return xmlDoc;
    }

    private void CheckUrlNode(XmlNode xmlNode, XmlDocument xmlDoc)
    {
        var urlList = new List<string>() { xmlNode("loc").InnerText };

        var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
        nsmgr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");

        var hrefLangUrls = xmlNode
            .SelectNodes("xhtml:link", nsmgr)
            .Cast<XmlNode>()
            .Select(x => x.Attributes("href").Value);

        urlList.AddRange(hrefLangUrls);

        foreach (var url in urlList)
        {
            string logMessage;
            if (!CheckUrl(url, out logMessage))
            {
                Log(logMessage);
            }
        }
    }

    private bool CheckUrl(string url, out string logMessage)
    {
        logMessage = null;
        try
        {
            var request = HttpWebRequest.Create(url) as HttpWebRequest;
            request.Timeout = 5000; //set the timeout to 5 seconds to keep the user from waiting too long for the page to load
            request.Method = "HEAD"; //Get only the header information -- no need to download any content

            using (var response = request.GetResponse() as HttpWebResponse)
            {
                int statusCode = (int)response.StatusCode;
                if (statusCode == 200) //Good requests
                {
                    return true;
                }
                else
                {
                    logMessage = String.Format("<a href='{0}'>{0}</a>, status code: {1}", url, statusCode);
                    return false;
                }
            }
        }
        catch (WebException ex)
        {
            logMessage = String.Format("<a href='{0}'>{0}</a>, status: {1}", url, ex.Status);
        }
        catch (Exception ex)
        {
            logMessage = String.Format("Could not test url {0}, exeption message: {1}", url, ex.Message);
        }

        return false;
    }

7 – What is the best solution to generate sitemap for multiple sites using Domain Access module?

We were using Domain Access module for multisiting.
For generating sitemap.xml file for we have applied a module. It has a manual that we have already applied.

Currently wesite shows on /admin/config/search/xmlsitemap that sitemaps are created.

enter image description here
But while visiting domainname/sitemap.xml we are getting 404 error. Any workaround needed to sitamaps to be shown?

Any suggestions and help appreciated. Thanks.

mobile application – What are the best tools for creating a Sitemap?

I am working on a mobile app and I have drawn a sitemap for it on paper. However, I want to to create a digital version of the sitemap. I have used Adobe Illustrator previously to create diagrams like this; however I have found that creating such diagrams on Illustrator is very time-consuming. I am looking for a faster way to create sitemaps.

I was wondering if anyone had any recommendations on any good free online tools for creating sitemaps? Any insights are appreciated.

8 – How do I debug/kint Simple XML Sitemap link array?

I am trying to find how I can debug/kint a variable/array from the Simple XML Sitemap?

I worked through the documentation here: https://www.drupal.org/docs/8/modules/simple-xml-sitemap/api-and-extending-the-module#s-api-hooks to find the hook I need.

My goal is to unset any links that have node/ to remove published, but un-aliased nodes of included content types.

The array key ('path') looks to be the unaliased URL and the below code removes all links except the home page. I am unsure how I can kint($link) in this function so I can see what other array keys are available to see what else I may use for comparison.

function HOOK_simple_sitemap_links_alter(array &$links, $sitemap_variant) {

  foreach ($links as $key => $link) {
    if (strpos($link('meta')('path'), 'node/') !== FALSE) {
      unset($links($key));
    }
  }
}

Is there a way to kint() these sitemap arrays? Or maybe some documentation that shows the structure of these arrays?

Fast 404 throws page not found for sitemap

I am using fast_404 module. My site uses simple_sitemap module to generate sitemaps.
I have three sitemaps generated: sitemap.xml, /categories/sitemap.xml and /brands/sitemap.xml
The first sitemap is working as expected but the categories and brands sitemaps throws 404 error (fast_404 html page) when the fast_404 is enabled. Is there any way to prevent 404 on those two sitemap URLs?