Remove index.php from ExpressionEngine URL’s

The contents of this article may be out of date. It has been archived and will no longer be updated, comments are closed and the page is provided for reference purposes only.

By default, ExpressionEngine adds 'index.php' into URLs before the name of any template groups. This results in a nice clean URL like becoming A minor annoyance it may be but I have been used to Textpattern handling URI's in a much more elegant manner. Luckily there are a few solutions.

Exclude Method

My preferred method of removing ‘index.php’ from ExpressionEngine URLs is to use the ‘exclude’ list method as it best fits my needs, however it might not be right for your needs so do read on before you decide. This method is best used if you don’t have too many directories outside your EE install and make use of multiple weblogs.

Your .htaccess file should contain:

RewriteEngine on
RewriteCond $1 !^(images|system|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]

Note: Remember to change the name of the system directory if you changed it during setup. There is no need to add your path.php file as it should not be accessed via a users browser and therefore any rewrite rule does not apply.

Include Method

Another option is to include template groups that we want to apply our rewrite rule to. This method os probably best if you are only using a single template group or have a number of directories outside your EE install that change regularly.

Your .htaccess file should contain:

RewriteEngine on
RewriteCond $1 ^(weblog|member|search|Forum_Name|TemplateGroup_Name|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]

By using either of the above methods we need to then tell EE what we have done. To do this we will need to go to Control Panel Home > Admin > System Preferences > General Configuration, and delete the ‘Name of your site’s index page’ value that is normally ‘index.php’. Leaving it completely blank.

In the future you will need to keep your .htaccess file up-to-date adding new directories if using the ‘exclude’ method or adding new templates if using the ‘exclude’ method.

Lastly it’s a good idea to reflect the changes on your URL structure in your robots.txt file. If you don’t already have you you should consider adding one after using either of the above methods. Create a simple text file in the root of your domain named robots.txt, it then controls the behaviour of search engine robots like Googlebot.

User-Agent: *
Disallow: /index.php/

This code tells searchbots to ignore webpages in the ‘directory’ /index.php/. This isn’t a directory at all. It does however contain a duplicate of every file on your website! It is best to avoid duplicate content.

More information and alternative solutions to the index.php problem can be found in the ExpressionEngine wiki.

This article was posted on 12 June 2009 in Code, ExpressionEngine, Tutorials


What you have had to say about all this...

This is a really good theme. I find it difficult to get great themes for expression engine blogs. With Wordpress its very simple but most from the ee themes I wind up with have errors or just look poor. I ought to learn to code one myself really

- una

That's the end of this article. I hope you found it useful. If you're enjoyed this article why don't you have a look around the archives, where you can find some more tutorials, tips and general ramblings.