Part of the EllisLab Network

Blog & News

Leslie Camacho
President, EllisLab

Better 404s with Strict URLs

Note: Strict URLs changed between this posting and the release of 1.6.5. Please see the Strict URLs section of the User Guide for details.

Originally planned as a feature for 2.0, Strict URLs will be sneaking into EE 1.6.5 (due soon). So this time around you get a preview of a 2.0 feature that you won’t have to wait for 2.0 to start using.

ExpressionEngine already has a number of ways to handle 404 pages but one of the most requested features from Search Engine Optimization (SEO) specialists has been the ability to “lock down” EE’s URL structure to enforce a more traditional use of 404 pages and help avoid inadvertent “Duplicate Content Penalties” from Search Engines. If you’re interested in learning more about what exactly that is, SEOmoz has a Illustrated Guide.

For example, say your Default Template Group is called “site” and you have a template called “news” in the same Template Group. Currently, EE will render the same content from both these URLs, assuming that you do not have a “news” Template Group:

http://example.com/index.php/site/news/
http://example.com/index.php/news/

This happens because if the first URL segment that EE encounters is not a valid Template Group, it will look for a Template of the same name in the default Template Group instead. If a person has coded both links in the site, the result can be that a search engine will think there is a duplicate content situation.

Another scenario where Strict URLs is useful is delivering 404s when the URL is manipulated by the user. For example, say someone attempts to go to the news portion of a site, but misspells part of the URL.

http://example.com/index.php/news/sprts/

There is no Template called “sprts”. Currently EE will ignore the misspelling and display this instead:

http://example.com/index.php/news/index/

When Strict URLs are enabled EE will display the specified 404 page and send 404 headers in both these situations.

http://example.com/index.php/404/

Here are the exact rules governing Strict URLs.

If no segments are found in the URL, your default template will be shown.

If the first segment exists and does not correlate to a valid Template Group, ExpressionEngine will display a 404 page and send 404 status headers.

If the second segment exists and does not correlate to a valid Template, ExpressionEngine will display a 404 page and send 404 status headers.

Our official recommendation will be that people enable Strict URLs but for legacy reasons it will be disabled by default. Please note that if you decide to use Strict URLs all the “path” variables in your templates must specify the template group and the template, like this:

{path='weblog/index'}

This is what we’ve always recommended. It also means that you will no longer be able to “short cut” around the default site Template Group.