Redirection in the absence of the last segment

I have one URL structure, for example:

www.site.com/template_group/template_1/entry_id

But I want it to be:

www.site.com/template_group/template_1/entry_id/url_title.

Entry_id will be the segment root of exp: channel: entries. How to redirect the site www.site.com/template_group/template_1/entry_id to the site www.site.com/template_group/template_1/entry_id/url_title.

Thanks a lot!

+6
source share
3 answers

Something like the following should work - it has not been tested, but it will give you a good idea of ​​how to move forward.

{if segment_4==""} {exp:channel:entries channel="x" limit="1" dynamic="no" entry_id="{segment_3}"} {redirect="template_group/template_1/{entry_id}/{url_title}"} {/exp:channel:entries} {/if} 
+12
source

put this at the very top of your template:

 {if segment_4 == ""} {exp:channel:entries channel="channel_goes_here" entry_id="{segment_3}"} {redirect="{site_url}/{segment_1}/{segment_2}/{segment_3}/{url_title} {/exp:channel:entries} {/if} 

This will check if you installed the fourth segment, if it does not occupy the third segment containing your entry_id, passes it to the channel record tag, which returns the desired url_title. With this url_title you can easily redirect to the correct page.

+5
source

Good answers from janvl and madebyhippo

A quick note if you use complex conditional expressions (the ones in the answers are simple, so you won't have this problem) is that EE will parse the channel record tags that they contain, which can slow down performance.

If you find yourself in this situation, it’s best to avoid the problem altogether with Mark "The croxton" add-ons such as switchee or ifelse

+4
source

All Articles