Skip to main content

Looking for a basic, EE focused .htaccess file without the overhead of an add-on? We've got you covered.

# Standard .htaccess file

# Secure .htaccess file
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

# Don't show any directory without an index file
Options -Indexes

# Dont list files in index pages
IndexIgnore *

# EE 404 page for missing pages
# May differ depending on where your template is located.
ErrorDocument 404 /index.php?/site/404

# Enable Rewrite Engine
RewriteEngine On
RewriteBase /

# Remove the www from the URL
# You may be able to do this through your web host or you may not need it at all.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Force the www (not used here but listed for reference)
# RewriteCond %{HTTP_HOST} !^www\.
# RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

# Remove index.php
# Uses the "exclude method"
# http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Exclude_List_Method
# This method seems to work best for us, you might also use the include method.
# http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method
# Exclude root files
RewriteCond $1 !^(favicon\.ico|index\.php|path\.php|php\.ini) [NC]

# Exclude EE folders
RewriteCond $1 !^(system|images|themes)/ [NC]

# Exclude 3rd party folders
RewriteCond $1 !^(css|js|assets)/ [NC]

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

# Remove IE image toolbar
<FilesMatch "\.(html|htm|php)$">
  Header set imagetoolbar "no"
</FilesMatch>