3

Is it possible to remove the template group from the url so instead of http://example.com/blog/article/postone it would be http://example.com/blog/postone. I already stripped the index.php via .htaccess.

My blog/index code:

{exp:channel:entries channel="blog" limit="8" orderby="date" sort="desc"}
  <h1>{title}</h1>
  <p>{blog_except}</p>
  <p><a href="{title_permalink='blog/article'}">{title}</a></p>
{/exp:channel:entries}

And my blog/article code:

{exp:channel:entries channel="blog" limit="1"}
  <h1>{title}</h1>
  <p>{blog_body}</p>
{/exp:channel:entries}

Thank you.

2 Answers 2

0

This is just simple routing so I'd look to use Freeway here. Then you can just map up the desired URL with the actual URL like this:

blogs/{{entry}} => blog/article/{{entry}}

Then people will be able to visit blogs/entry-title and EE will treat it as if they visited blog/article/entry-title and use the appropriate template_group/template.

4
  • As another alternative and as Freeway's younger brother is Freebie which would also do the job for your use case.
    – Ian Young
    Commented Apr 23, 2013 at 11:50
  • Thank you Ian. This seem to be a nice Addon that could solve my issue with the URI. Thank you for your suggestion. Have a nice day.
    – user1292
    Commented Apr 23, 2013 at 13:07
  • with this example, what happes to blogs/P12 (pagination)?
    – GDmac
    Commented Apr 23, 2013 at 14:04
  • I did not implement this yet as I am new to ExpressionEngine. I just display 8 entries and make a like to a archive to see the rest as per year on title.
    – user1292
    Commented Apr 24, 2013 at 18:24
3

In the past i used to have an elaborate {exp:switchee} tag in de blog/index template, that would check for various possibilities for segment_2. Process a channel:entries tag accordingly, wether it is a number (archives), or pagination (P12), otherwise treat it like a url_title. (pseudo code)

{exp:switchee variable="{segment_2}" parse="inward"}
{case value="#/d+#"}
  // number means archives
  // process further? e.g. months etc. 2012/04
{/case}
{case value="''|#^P/d+#"}
  //pagination or empty (meaning index)
{/case}
{case default="yes"}
  // not empty, expecting url_title
{/case}
{/exp:switchee}

Edit: But actually, i went back to more separate templates for detail views (single entry), archives and listviews. Not have one huge index template anymore.

2
  • I prefer using switchee to accomplish this. It's relatively easy to understand and if you comment your templates correctly easy to maintain in the future.
    – CreateSean
    Commented Apr 23, 2013 at 10:57
  • Thank you GDMac for the solution, however, this seems much complicated than the solution Ian posted above. Thank you for your suggestion and have a nice day.
    – user1292
    Commented Apr 23, 2013 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.