Search code examples
codeigniterexpressionengine

expressionengine URL rewrite 2.3.1


In EE 2.2.2 having this in my htaccess file

RewriteRule ^(.*)$ /index.php/view/$1 [L] 

Allowed me to rewrite domain.com/index.php/view/phone to domain.com/phone.

In EE 2.3.1 this no longer works. The problem seems to be with system\codeigniter\system\core\URI.php and I see few things has changed with this file. If I replace URI.php with the 2.2.2 version then it works again. My question is what has changed and how do I get this to work again.


Solution

  • Updated answer

    After some time with thoughts (and testing) I've come up with an alternate solution, that might fit your need with the updated EE.

    Assuming your rewrite rules are like the following:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    Now, my suggestion is to let your view template group be the index template group. In your index template in the view template group, you could have the following:

    {exp:channel:entries channel="view_channel" require_entry="yes"}
    {if no_results}
    {embed="a_template_group/my_normal_frontpage"}
    {/if}
    <DOCTYPE html>
    <html>
        <head>
            <title>{title}</title>
        </head>
        <body>
            <h1>{title}</h1>
        </body>
    </html>
    
    {/exp:channel:entries}
    

    This allows you to, without adding other rewrite rules, have your visitors go to http://example.org/phone and the view/index template will try to find the entry with the entry ID labeled 'phone'. If that entry cannot be found (the {if no_results} part) embed another template. In this case I would assume you'd like to show some sort of frontpage.

    This also allows you to, under the view template group, create ordinary templates like view/create_entry which will show up, when you go to http://example.org/create_entry

    This should work - and is easy customizable to fit your needs.