0 users online. Create an account or sign in to join them.Users

Search

This very simple XSLT utility will go through your pages and add the ones that are not hidden and not admin type to a urlset. The sitemaps protocol is supported by Google, Yahoo!, and Microsoft. Submit the URI to search engines to increase the searchability of your website.

Usage

Create a new page and be sure to include the navigation data source. Copy and paste the code from the gist.

Modify the code to add specific arguments to specific pages, see http://www.sitemaps.org/protocol.php for more info.

Download

http://gist.github.com/106555

More info

http://www.sitemaps.org

Great timing carsten, I happened to code this exact same requirement earlier today. I might have a slightly neater way of building the URL handle:

<xsl:template match="page" mode="sitemap">
    <url>
        <loc>
            <xsl:value-of select="concat($root,'/')"/>
            <xsl:for-each select="ancestor::page | current()">
                <xsl:value-of select="concat(@handle,'/')"/>
            </xsl:for-each>
        </loc>
    </url>
    <xsl:apply-templates select="page[not(types/type = 'hidden') and not(types/type = 'admin')]" mode="sitemap"/>
</xsl:template>

Instead of passing the $root each time, there is a loop through all parent page nodes of the current page. Same outcome, just a different approach.

Should the second apply-templates within the last template also check the page type is not hidden/admin?

Thanks for sharing this. With these utilities, building potentially tricky pages becomes so much easier :-)

I don't know what is the best approach (probably yours), but since my Xpath skills are not that good I went for this approach.

I wonder how big the added value would be of making an extension that allows you to enter the lastmod, changefreq, and priority attributes.

Isn’t the point of a sitemap to map out all pages (entry detail view etc.), not just sections (what Symphony refers to as “Pages”)?

Yes it is. This is actually more of a starting point for a complete sitemap. I use this XSLT but call several other templates in the <urlset> for other projects to indeed include entry detail views. However, since there is no real standard section setup for every project I did not put this code in the XSLT utility.

To generate entry detail views or other sitemap urls from any of your section entries do something like this (the following is also depending on URL parameters):

<xsl:template match="products/brands/entry">
    <xsl:call-template name="sitemap-url">
        <xsl:with-param name="sitemap-url" select="concat($root, '/products/', ../@link-handle, '/', @id, '/')" />
    </xsl:call-template>
</xsl:template>

When doing this, make sure to add the following to your .htaccess-file above ### FRONTEND REWRITE:

# Sitemap.xml redirect
RewriteCond $1 ^sitemap.xml
RewriteRule ^(.*)$ index.php?symphony-page=sitemapxml [L]

This will redirect the call to sitemap.xml to the page with the handle ‘sitemapxml’ (since Symphony doesn’t allow a dot (.) in the handle). This way when you navigate to yourdomain.com/sitemap.xml the sitemap will get shown.

Also, isn’t it an idea to include this sitemap.xml-information in the documentation?

What if I needed 4 xml files? would the RewriteCond $1 ^sitemap1.xml by incremented to $2 ^sitemap2.xml etc??

Not sure, I'm not a .htaccess / rewriteEngine genius, but I would guess you would just have to copy/paste the 2 lines 4 times to fit your needs:

RewriteCond $1 ^page1.xml
RewriteRule ^(.*)$ index.php?symphony-page=page1 [L]

RewriteCond $1 ^page2.xml
RewriteRule ^(.*)$ index.php?symphony-page=page2 [L]

RewriteCond $1 ^page3.xml
RewriteRule ^(.*)$ index.php?symphony-page=page3 [L]

RewriteCond $1 ^page4.xml
RewriteRule ^(.*)$ index.php?symphony-page=page4 [L]

Even simpler

RewriteCond %{REQUEST_URI} .xml$ [NC]
RewriteRule ^(paged{1,4}).xml$ index.php?symphony-page=$1 [L]

This would only work from the root of the site, and do from 1 to 9999.

Disclaimer (untested, just got out of bed).

:) cheers guys.. not a .htaccess guru myself either.. defo would be good to have this kind of stuff in docs for noobs to know sitemaps are possible with this approach :)

Outputting XML is possible anyway. Using a .xml URL suffix is just a matter of taste, and by no means Symphony-related.

That's cool. Does Google read domain.com/sitemap as well as domain.com/sitemap.xml or does it prefer a file extension?

...nobody know what google prefers... 8-|

@designermonkey: Not bad, but you need to add a backslash to make it work:

RewriteCond %{REQUEST_URI} .xml$ [NC]
RewriteRule ^(page\d{1,4}).xml$ index.php?symphony-page=$1 [L]

The condition is useless (because you only match pages with ".xml" suffix anyway), so you can make it one line:

RewriteRule ^(page\d{1,4}).xml$ index.php?symphony-page=$1 [L]

Next step: You don't need the "index" type rewrite, you can simply use the page URL:

RewriteRule ^(page\d{1,4}).xml$ /$1/ [L]

[EDIT]: Now I see, the forum is eating those backslashes! I finally managed to have them in the above code by escaping them -- typing "\\".

@michael-e that's great! makes for neater efficient code. It's working a treat on my dev server.. woop woop.

Final version -- we shouldn't use the leading slash:

RewriteRule ^(page\d{1,4}).xml$ $1/ [L]

[EDIT]: I verified that now this works if Symphony is installed in a sub-directory of your webspace.

Would the above work for deep level urls? domain.com/page/subpage/thisisxml.xml ?

No, it assumes that your page starts with "page", and it's on the root level.

Do you want to make it work with any ".xml" type URL? What's the ruleset you have in mind?

Possible ruleset #1: The page name starts with "page", but the page can be anywhere in the hierarchy:

RewriteRule ^(page\d{1,4}).xml$ $1/ [L]
RewriteRule ^(.+)/(page\d{1,4}).xml$ $1/$2/ [L]

Possible ruleset #2: No special naming convention. Every URL that has a ".xml" suffix should be mapped to a corresponding Symphony URL. Please note that I do not recommend this, because you will have "duplicate content", and it's nonsense to have working URLs with a ".xml" suffix for every (HTML) page! So I am only adding this in order to give you another example of how rewrites can work:

RewriteRule ^(.+).xml$ $1/ [L]

I think you get the point.

I'm not sure about that \d{1,4}. It will match 1 all the way up to 9999 as \d{1,4} means "at least one, at most four decimals".

I'd suggest the following:

RewriteRule (page[1-4]).xml$ $1/ [L]

Again, without having tested it. But in theory it should match any URL that ends with page1.xml, page2.xml etc. and chops off the .xml part.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details