Htaccess File


#add handler that allows html, xml, and json to work dynamically as PHP
#AddType application/x-httpd-php .html .xml .json
AddHandler php5-script .html .xml .json

#serve all resources labeled as 'text/html' or 'text/plain' with the media type 'charset' parameter set to UTF-8'
AddDefaultCharset utf-8

#serve correct media type (MIME type) for resources
AddType application/atom+xml .atom
AddType application/json .json
AddType application/ld+json .jsonld
AddType application/oebps-package+xml .opf
AddType application/rss+xml .rss
AddType application/xml .rdf .xml
AddType application/ .eot
AddType application/x-font-ttf .ttc .ttf
AddType font/ttf .ttf
AddType font/opentype .otf
AddType font/otf .otf
AddType application/font-woff .woff
AddType font/x-woff .woff
AddType application/font-woff2 .woff2
AddType image/svg+xml .svg
#set custom error page for Apache to return
ErrorDocument 404 /book/opsis/404.html

#compress html, css, javascript, font, and miscellaneous resources
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE "text/css" "text/html" "text/javascript" "text/plain" "text/xml" "application/x-javascript" "application/javascript" "application/json" "application/ld+json" "application/rdf+xml" "application/rss+xml" "application/x-font-woff" "application/x-font-ttf" "application/" "font/eot" "font/opentype" "font/otf" "font/ttf" "font/x-woff" "image/bmp" "image/jpeg" "image/svg+xml" "image/" "image/x-icon" 

#remove `ETags` as resources are sent with far-future expires headers
#`FileETag None` doesn't work in all cases.
<IfModule mod_headers.c>
  Header unset ETag

FileETag None

#set expires headers to improve caching
<IfModule mod_headers.c>
  ExpiresActive on
  ExpiresDefault "access plus 1 month"

  ExpiresByType text/css "access plus 1 year"

  #Data interchange
  ExpiresByType application/atom+xml "access plus 1 hour"
  ExpiresByType application/rdf+xml "access plus 1 hour"
  ExpiresByType application/rss+xml "access plus 1 hour"
  ExpiresByType application/json "access plus 0 seconds"
  ExpiresByType application/ld+json "access plus 0 seconds"

  #Favicon (cannot be renamed!) and cursor images
  ExpiresByType image/ "access plus 1 week"
  ExpiresByType image/x-icon "access plus 1 week"

  ExpiresByType text/html "access plus 0 seconds"

  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType application/x-javascript "access plus 1 year"
  ExpiresByType text/javascript "access plus 1 year"

  #Media files
  ExpiresByType audio/ogg "access plus 1 month"
  ExpiresByType image/bmp "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType image/webp "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/ogg "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"

  #Web Fonts
  #Embedded OpenType (EOT)
  ExpiresByType application/ "access plus 1 month"
  ExpiresByType font/eot "access plus 1 month"

  ExpiresByType font/opentype "access plus 1 month"

  ExpiresByType application/x-font-ttf "access plus 1 month"

  #Web Open Font Format (WOFF) 1.0
  ExpiresByType application/font-woff "access plus 1 month"
  ExpiresByType application/x-font-woff "access plus 1 month"
  ExpiresByType font/woff "access plus 1 month"

  #Web Open Font Format (WOFF) 2.0
  ExpiresByType application/font-woff2 "access plus 1 month" 

#rewrite rules for URLs and directory patterns
<IfModule mod_rewrite.c>
  #Options +FollowSymLinks
  #Options +SymLinksIfOwnerMatch
  RewriteEngine On

  #check for 200 header, legitimate url 
  RewriteCond %{ENV:REDIRECT_STATUS} 200
  RewriteRule .* - [L]

  #change to
  RewriteBase /book/opsis/
  RewriteRule item/([-_a-zA-Z0-9]+) item.html?id=$1 [L,QSA]

  #remove need to have .html extension in filename
  RewriteCond %{REQUEST_FILENAME}.html -f
  RewriteRule ^(.*)$ $1.html [L,QSA]

#redirect from the `http://` to the `https://` version of the URL.

#<IfModule mod_rewrite.c>
#  RewriteEngine On
#  RewriteCond %{HTTPS} !=on
#  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Exit mobile version