Skip to content

Instantly share code, notes, and snippets.

@jeromecoupe
Created December 2, 2013 02:02
Show Gist options
  • Save jeromecoupe/7743805 to your computer and use it in GitHub Desktop.
Save jeromecoupe/7743805 to your computer and use it in GitHub Desktop.
My .htaccess for ExpressionEngine
# 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 404 template is located.
# -------------------------------------------------
ErrorDocument 404 /index.php?/site/404
<IfModule mod_rewrite.c>
# Enable Rewrite Engine
# -------------------------------------------------
RewriteEngine On
RewriteBase /
# Remove the www from the URL (not used here but listed for reference)
# 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
# -------------------------------------------------
# RewriteCond %{HTTP_HOST} !^www\.
# RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# 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 !^(index\.php|admin\.php|favicon\.ico) [NC]
# Exclude EE folders
# -------------------------------------------------
RewriteCond $1 !^(assets|images|themes)/ [NC]
# Remove index.php
# -------------------------------------------------
RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC]
RewriteCond %{QUERY_STRING} !^(URL=.*)$ [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
</ifModule>
# Remove IE image toolbar
<FilesMatch "\.(html|htm|php)$">
Header set imagetoolbar "no"
</FilesMatch>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 second"
ExpiresByType text/css "access plus 5 minute"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-download "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
<ifModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2419200, public"
</filesMatch>
<filesMatch "\\.(css)$">
Header set Cache-Control "max-age=300, public"
</filesMatch>
<filesMatch "\\.(js)$">
Header set Cache-Control "max-age=2419200, private"
</filesMatch>
<filesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=2419200, public, must-revalidate"
</filesMatch>
<filesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=3600, private, must-revalidate"
</filesMatch>
</ifModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment