2

I have a site that is using the simplest of URL layouts and was just asked if they could change.

Currently, they are as follows:

www.domain.com/details/item
www.domain.com/dates/item
www.domain.com/topics/item

Where 'item' is a separate entry that is linked via playa field. So all links are simply

www.domain.com/template_group/index

and 'item' is {last_segment} which triggers the entry {url_title}

Now they would like to shift this to

www.domain.com/item/details
www.domain.com/item/dates
www.domain.com/item/topics

Is there something simple I am missing? I feel that each time I look at it, I start to over complicate it.

3
  • That's a tough switch, as you would need to have all the logic for your 'item' pages on your site index template. It would be great if they could at least go with domain.com/items (template group)/item-name (entry) /details etc...Can you be more specific as to what part of the change you want help with? Jul 4 '13 at 17:34
  • 1
    I had thought it may be doable with a forced rewrite in .htaccess, i.e. RewriteRule (.*)/details$ /index.php?/details/$1 but sadly EE seems to use the segments from the original request, not the rewrite. Jul 4 '13 at 22:11
  • Dave, I was trying the likes of the same. No luck here though in QA.
    – W3bGuy
    Jul 5 '13 at 14:51
0

So, this is dirty, but seems to be working locally anyway. There may be much tidier solutions but they escape me.

In your home template, try using something like:

{if segment_2}
    {embed="{segment_2}" target="{segment_1}" /}
{/if}

This assumes you have a template group with the template set in segment 2 (i.e. details, dates, etc.). It may be prudent to add some additional logic to ensure the request is valid.

Then, again assuming you only want one entry on the details page, you can use:

{if embed:target}
    {exp:channel:entries channel="items" limit="1" url_title="{embed:target}"}
        Some code...
    {/exp:channel:entries}
{/if}

Theory being that all requests to non-existent stuff gets forwarded to the home template (so the old paths of /details/item should still work). Then the home template picks them up and embeds the template you actually want.

1
  • Dave, this worked for me on QA as well. While I also agree with James about "fighting" EE, it beats rebuilding a simple site for now. Thanks.
    – W3bGuy
    Jul 5 '13 at 14:56
0

Whilst it's possible to achieve what you're looking for via any number of techniques (htaccess, pages module, convoluted embeds), I wouldn't recommend doing this at all. You'll end up fighting against EE the whole way, and if the site grows in complexity you'll have a maintenance nightmare on your hands. At a minimum, you'll need to specify a template in segment 1 and an entry in segment 2, so /items/item/dates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.