1

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] 

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Makes complete sense. Thanks a ton. What if I had a variable on the end. Something like '/feature/article/{variable_article_name}/' How would I "move" the {variable_article_name} from the request to the rewrite?
Now we're talkin! Works great. Thanks for the insight.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.