Expression Engine Design

Thursday, March 13, 2008

This site is an example of removing index.php and, the template group from the url’s in ExpressionEngine. It has been said that one cannot do this and have proper 404’s. It seems one can.

ExpressionEngine URL’s

To have a logical url structure throughout the site of domain.com/categoryname/article-title/,
Use separate templates named after the categories to create a custom url structure category-name/article.

For a very large site I would recommend to use separate weblogs, in which case obviously removing template group name is not an option. When doing this name the template group after the category names wanted and it does the same thing.

Disadvantage: Having to create a separate template or template group for each category or weblog. Where this is not a problem then all is well. Where it is, one has to have the setting: Use category names? set to yes and use a category trigger word, category is the default but it can be renamed to anything wanted.

Admin › Weblog Administration › Global Weblog Preferences

Use Category URL Titles In Links?
This preference determines whether the category ID number or the category URL Title is used in category-related links. Yes No
Category URL Indicator
If you set the above preference to “yes” you must choose a reserved word. This word will be used in the URL to indicate to the weblog display engine that you are showing a category. Note: whatever word you chose CAN NOT be the name of a template group or a template.

On this example, in htaccess I am removing the index.php and the template group from the url’s. As well, using conditionals I am using one template for each category, named after the category. Then I add a nice Breadcrumb at the top to show where one is and provide a path back.

The the read more links use the same template to show the entire article as well using conditionals with segments.
For menus using the category_id in the entries tag in each template limits what is shown to that category.

Using a couple extra lines of code all 404’s work properly and are served as 404, not 200 (file found),
Not doing this causes:
Search engines don’t update for pages not there.
All 404’s point to one page, which is duplicate content if not a proper 404.

Reference: what is a result code and why should I care?.
If one is thinking of doing this, read the article in the knowledge base for pitfalls.

Removing the template group works if there is only one weblog. Adding additional templates using category names can bring benefits as shown here. It’s a way to have categories with a friendly url structure named after the category. Another way is to use separate weblogs named the same way and using the index template for everything in each, or adding categories as well.

Structure here:
Main index (this page)
category = index - hidden in category list using show="not 4” ...where 4 is category id.
Blogging category - template name - blogging - weblog:entries tag - category="3" ...
programming category - template name programming entries tag - category="4"
etc…

Many familiar with EE will be surprised to click on a category name in the menu and have the category name in the url. Normally it is either category id (C4), or has a trigger word category/category-name. But using the template name as category name skips this.
The downside of this is having to make a new template for each category, not a big deal usually.

Another way to do this with url’s is to name the template group appropriately, in this case if News and About was a separate weblog, I would name the template group news-about.
See docs on ExpressionEngine URLs

I have demonstrated this in News and Events. All articles in the News-events category have been removed from main area article lists, and the category removed from the category list.
One could have an rss feed for only the News and Events category as well. News and Events RSS.

EE has many ways to arrive at the same place.
I could have made separate weblogs and template groups to do this, using the index file the same way, replacing the category name here with the weblog template-group name.

Expression Engine is highly configurable so there are many paths to arrive at the same place. In this example, content is separated by category, and a category can be removed from the category list (news-events).
For more on this, see this article in the EE wiki comparing separate weblogs or categories.
One cannot have separate weblogs and also remove the template group name from the url.

Categories

Syndicate

Search