.htaccess (Boilerplate)

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

# SET DEFAULT CHARSET
AddDefaultCharset utf-8
AddCharset utf-8 .txt
AddCharset utf-8 .xml

# REDIRECT ROOT ONLY
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://target.com/ [L,R=301]

# FILE SECURITY
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

# PERMANENT REDIRECT
RedirectPermanent /directory http://domain.com/target

# EXPIRE HEADERS
# A2592000 = 1 MONTH
# A604800 = 1 WEEK
# A86400 = 1 DAY
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault A604800
  ExpiresByType application/x-javascript A2592000
  ExpiresByType application/x-shockwave-flash A2592000
  ExpiresByType application/pdf A2592000
  ExpiresByType image/x-icon A2592000
  ExpiresByType image/gif A604800
  ExpiresByType image/png A604800
  ExpiresByType image/jpeg A604800
  ExpiresByType text/plain A604800
  ExpiresByType video/x-flv A604800
  ExpiresByType text/html A86400
  ExpiresByType text/css A86400
</IfModule>

# COMPRESSOR
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# SET HEADERS
<IfModule mod_headers.c>
  Header set Vary Accept-Encoding
  
  <Files ~ "\.(txt|xml)$">
    Header set X-Robots-Tag "noindex"
  </Files>
  <FilesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </FilesMatch>
  <FilesMatch "\.(css)$">
    Header set Cache-Control "max-age=2592000, private"
  </FilesMatch>
  <FilesMatch "\.(js)$">
    Header set Cache-Control "max-age=2592000, private"
  </FilesMatch>
  
  Header unset ETag
</IfModule>

FileETag None

# DISPLAY SVG IMAGES
AddType image/svg+xml svg svgz
AddEncoding gzip svgz

Other Posts