Hoping you could all help a little, had a look around https://docs.expressionengine.com/v2/ but could not find much of an answer.

I've just inherited a website currently on expression engine v2.10.1 and while I don't really know anything about expression engine or the CP I can see the set up is a bit of a mess. There are a bunch of unused old pages that are still live and the site needs a good spring clean, I've found out how to unpublish them but would obviously like to redirect them instead.

I researched around and found a .htaccess file (12 actually but only 1 with content) and tried to add a line into the # Redirects area

Redirect 301 http://company.com/old-page http://company.com/new-page

This does not seem to be working, any lesson or links to a missed duplicate answer would be greatly appreciated!

Steve

  • Depends what you are calling a 'page'. EE does not really have 'pages' in the way that things like Wordpress do - content is stored within a database and then published via templates - design and content are quite separate in EE. If you could clarify what it is you are referring to as 'pages' it will be easier to give you a sensible answer. – jcogs.eecms Dec 3 at 18:55
  • Hi jcogs. Thanks for the lesson on EE, I've not used a content database system before so this will be new ground for me. I guess to clarify, when I said page I meant a single URL, landing page, etc – Brink Dec 4 at 10:11

If you use the htaccess.. use the one on the root it should work. If you change the Status of the unused pages to Closed.. the pages shouldn't show up.. But if there's links to theses pages you will get a 404 or a redirection.

  • Thank's Benoit, as I will be creating new pages on a different system and sub.domain I will close these pages down and attempt htaccess again, how many htaccess files should I expect to see in the root? – Brink Dec 4 at 10:06
  • There is only one .htacccess file, but you can define multiple redirections within it. – jcogs.eecms Dec 4 at 10:14

There are a few ways to do it... one as Benoit L mentioned, and I will throw up an example - if you happen to use Apache or LightSpeed webserver, this should work... the other way is through ExpressionEngine pages/templates itself (easiest way). Of course the more you know of the basics in the way ExpressionEngine works, the more sense this will make to you.

A single htaccess file, actually named .htaccess (with the "." prepending the name of the file) will override any webserver config files, this is why it exists. There should be only one named with the "." (period) in front of it.

USING HTACCESS FILES

A redirect from http://this_site.tld/old_content/this_page to http://this_site.tld/new_content/this_page could look like this:

# These will probably already exist in your .htaccess
# file and should only exist one time.
RewriteEngine On
RewriteBase /

# actual redirect example
RewriteRule ^old\_content\/this\_page$ "https\:\/\/this\_site\.tld\/new\_content\/this\_page" [R=301,L]

This is for a 301 redirect (permanently moved).

THE EXPRESSIONENGINE ALTERNATIVE

Alternatively you can handle this with EE as well. By redirecting entries, template groups, or both. It depends how many levels deep the existing page is. I will try to cover as many as I can think of off the top of my head. Starting simple and moving to slightly more complex scenarios.

Redirect a Single Entry to a Different Channel/ Template Group

template_group/entry_url

Using the same example urls as above, you want to move the entry titled this_page from the template group (channel) old_content to new_content. This method means that the actual template file old_content/index is what is used to render your content.

To redirect a single entry from this template group, would be done in one of two ways.

Actual Files: Going this route you would need to create an actual file for each redirected entry. In this case you would create the file called this_page from within the old_content template group. In this file you add the code to redirect this particular entry.

FILE: old_content/this_page

{redirect="new_content/this_page" status_code="301"}

Simple, right? Here's another way to achieve the same thing...

ExpressionEngine Conditionals: Going this route, you would use EE's {if} conditional statements to redirect the url from within the index template itself.

FILE: old_content/index

{if segment_2 == "this_page"}
    {redirect="new_content/this_page" status_code="301"}
{/if}

Cool... also pretty easy, but neither are the most efficient way to do it.

SO, if you wanted to move all entries to the new channel (this makes the most sense on many different levels)...

Redirect ALL Entries to a Different Channel/Template Group

This is the easiest and most efficient method, but only good in the event you want to redirect all entries out of old_content into new_content.

FILE: old_content/index

{if segment_2}
    {redirect="new_content/{segment_2}" status_code="301"}
{/if}

Awesome... all entries would redirect with 3 lines of code (or 1 line if you write it as such).

Okay... Typically I see entries that go three or more levels deep (each represented by a url segment) - for example consider the url http://this_site.tld/hot_topics/article/this_story - the url is 3 segments deep and uses a unique template file called article that exists in the hot_topic template group. The this_story is the dynamically generated {url_title} and exists as {segment_3}.

In this scenario, the template group is hot_topics, perhaps the hot_topics/index file exists to show a collection of your latest articles under this channel, so you decide to use another template to render your entire article - so you add the article template inside the hot_topics channel.

After some website restructuring you wish to redirect all of those entries to another channel (let's say the name of this channel is simply topics). The actual rendering template in this case will be called entry.

First you need to have created the entry template within the channel titled topics.

FILE: hot_topics/article

{if segment_3}
    {redirect="topics/entry/{segment_3}" status_code="301"}
{/if}

I could literally go on and on with specific examples. But I think you will need a nap after reading and trying to absorb this much at once, especially if you are new to EE. If you need more specific info, I'll be happy to help where I can.

Good luck.

You can do redirection in your .htaccess file or in the httpd.conf file within where your website is defined. In your syntax it looked like:

Redirect http://www.website1.com/page1 http://www.website2.com/page2

I typically do a root-relative link as my first website, so this is worth trying if that's not working:

Redirect /page1 http://www.website2.com/page2

Once you get that working, you can get fancier with RedirectMatch (https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirectmatch) to save time if you have multiple but similar pages.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.