ExpressionEngine 301 redirects made easier

So your ExpressionEngine sites URL’s have changed and you need to generate a list of 301 redirects, but what if you have hundreds, or even thousands of URL’s?

Here’s a dead simple way of generating your 301 redirect list, ready for you to paste into your .htaccess file.

Step 1 - create a template

Create a blank template. You can create the template in any template group you like, so long as you can call it from your browser.

Step 2 - add a tag or two

Open up your blank template. Now add channel entries tags for each channels’s entries you want to redirect. Here’s some basic examples:

Example 1 - for removing index.php

In this example index.php will be stripped from the URL.

{exp:channel:entries channel="mychannel"}
redirect 301 /index.php/blog/{url_title}/ {site_url}blog/{url_title}/<br>
{/exp:channel:entries} 

Outputs: redirect 301 /index.php/blog/entry_title/ http://mysite.com/blog/entry_title/

Example 2 - redirect to a new template group

In this example all URL’s will be redirected from /updates to /news.

{exp:channel:entries channel="mychannel"}
redirect 301 /index.php/updates/{url_title}/ {site_url}news/{url_title}/<br>
{/exp:channel:entries} 

Outputs redirect 301 /index.php/updates/entry_title/ http://mysite.com/news/entry_title/

Example 3 - redirect for old pages

In this example all entries that have a status of “closed” will be redirected to your home page.

{exp:channel:entries weblog="mychannel" status="closed"}
redirect 301 /index.php/site/{url_title}/ {site_url}<br>
{/exp:channel:entries}

Outputs redirect 301 /index.php/site/entry_title/ http://mysite.com/

Step 3 - try it!

Save your template then call it up in your browser. If all goes well you should see the text list of 301’s that you can copy/paste into your .htaccess file.

Naturally you can use all the available channel entries attributes to refine the output, and format the URL’s however you wish using entry variables.

You might also like

You don't know unless you ask

Contact me today