Search code examples
php.htaccessmod-rewriteexpressionengine

Remove index.php and add 301 redirects in .htaccess (ExpressionEngine)


A client has an expressionengine site and wants the 'index.php' removed. Doing this alone will put a dent in his sites SEO ranking since it will change all URLs. So, we want to retain link equity and social network share counts by adding a 301 to all pages.

I know how to remove the index.php and I know how to redirect (I think), but when I use them both, the server throws a redirect loop. My logic is warped. What am I missing here?

Here is what I'm working with:

# Redirect attempt
Redirect 301 /index.php/feature/article/ http://domain.com/feature/article/

# EE index.php rewrite
RewriteCond $1 !^(index\.php|js|path\.php|press_releases|rear|robots\.txt|text\.html|themes) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L] 

Solution

  • You only want to redirect if the actual request is for an /index.php/ URL. Change your Redirect directive to this:

    # Redirect attempt
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
    RewriteRule ^/?index.php/feature/article/(.*)$ http://domain.com/feature/article/$1 [R=301,L]
    

    This condition matches against the actual request that the server got and not the URI (which can get rewritten by the second rule).