Related Items Question

After two sunny weeks of vacation in Tuscany, i’d like to implement related items and need some help.

Three pieces of information:

  • I’m using the latest version of Elements
  • I’m using Pretty URLs
  • I’m using IIS, not Apache

This is my web.config (similar to the .htaccess file)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>

                <!-- 0) Fallback: / oder /index.php ohne item= - Redirect -->
                <rule name="ohne item oder slug - redirect" stopProcessing="true">
                    <match url="^(|index\.php)$" ignoreCase="true" />
                    <conditions>
                        <!-- nur wenn KEIN item=… gesetzt ist -->
                        <add input="{QUERY_STRING}" pattern="(?:^|&amp;)item=" negate="true" />
                    </conditions>
                    <!-- Hier Ziel-URL eintragen -->
                    <action type="Redirect" url="/" redirectType="Permanent" />
                </rule>

                <!-- 1) index.php?item=slug → /slug (Rewrite) -->
                <rule name="?item=slug → slug" stopProcessing="true">
                    <match url=".*" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                        <add input="{QUERY_STRING}" pattern="(?:^|&amp;)item=([^&amp;]+)" />
                    </conditions>
                    <action type="Rewrite" url="index.php?item={C:1}" />
                </rule>

                <!-- 2) /slug → index.php?item=slug -->
                <rule name="slug → index.php?item=slug" stopProcessing="true">
                    <match url="^([^/]+)/?$" ignoreCase="true" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php?item={R:1}" appendQueryString="true" />
                </rule>

            </rules>
        </rewrite>
    </system.webServer>
</configuration>

This is my site structure:

From the main page, all articles are correctly linked and displayed on the /articles/ page. Related items are displayed on each /articles/ page. I’ve specified the link using {{ item.url }}. However, it’s not being rendered/translated correctly:
https://www.cornrow.de/artikel/herr_grun_zieht_nach_lich/?item=unser_d-wurf_ist_da

The correct link should be:
https://www.cornrow.de/artikel/unser_d-wurf_ist_da

If i try the preview it works.

I think I’ve found the solution. Please don’t waste any more time thinking about it. I’ll post the solution once I’ve finished testing.

@dan @ben Related Item has a small problem with Pretty URL.

This only happen if the site is published because pretty url only work on webservers. This has nothing to do with IIS or apache.

without pretty url

The link to a post is .../post/?item=article
The browser show .../post/
Link to related item is .../post/?item=relatedarticle

with pretty url

The link to a post is .../post/article
The browser show .../post/article
Link to related item is .../post/article/?item=relatedarticle

thanks for the report! Do you have a project I could test this on? :slight_smile:

elementsapp://downloadDocument/4sIxDCToVhj0

This is Appleseed Daily with Related Items

Published: Jonny Appleseed's Blog

Fixed in Elements Version 1.5.4

thank you @ben

if anyone encounters problems, please clear browser cache

1 Like