ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Redirect /index/* to /*

August 06, 2012 4:59pm

Subscribe [2]
  • #1 / Aug 06, 2012 4:59pm

    Daniel Edwins

    1 posts

    I am launching a new site in ExpressionEngine. In the site’s previous CMS, the URL structure was /index/page-name. I would like to map the old pages to the new site so that the pages display so that /index/page-name is redirected to /page-name. I’m running into difficulty using the Apache Rewrite rules because /index/ is the default template for the default template group.

    Any ideas on how to accomplish this?

  • #2 / Aug 06, 2012 5:31pm

    Daniel Edwins

    1 posts

    I found an easy way to resolve this in ExpressionEngine instead of relying on the .htaccess file. At the top of my index template for my default template group, I put the following:

    {if segment_1 == "index" && segment_2}
     {redirect="/{segment_2}"}
    {/if}

    In this case, we have up to three layers of hierarchy, so this is what we’re using:

    {if segment_1 == "index" && segment_2 && segment_3 && segment_4}
     {redirect="/{segment_2}/{segment_3}/{segment_4}"}
    {if:elseif segment_1 == "index" && segment_2 && segment_3}
     {redirect="/{segment_2}/{segment_3}"}
    {if:elseif segment_1 == "index" && segment_2}
     {redirect="/{segment_2}"}
    {if:elseif segment_1 == "index"}
     {redirect="/"}
    {/if}

    And then we can simply add these redirects to our .htaccess file:

    # After EE rewrite code
    Redirect 301 /page_name <a href="http://domain.com/new_page_name">http://domain.com/new_page_name</a>


    It’s not ideal to have two redirects like this, but it does the job.

  • #3 / Aug 07, 2012 9:43pm

    Shane Eckert

    7174 posts

    Hey Daniel Edwins,

    I am glad that you were able to find a solution!

    If you need anything else, please just let me know by opening a new thread.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases