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
#AddHandler php5-script .html .xml .json
<FilesMatch "^(sitemap).xml$">
AddHandler php5-script .xml

#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
<Files "manifest.json">
AddType application/manifest+json .json
<Files "opensearch.xml">
AddType application/opensearchdescription+xml .xml
AddType application/atom+xml .atom
AddType application/json .json
AddType application/ld+json .jsonld
AddType application/rdf+xml .rdf
AddType application/rss+xml .rss
AddType application/xml .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

#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/manifest+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" 

#remove the 'X-Powered-By' response header set by some frameworks and server-side languages
#security measure - its value contains information about them: name, version number, etc.
<IfModule mod_headers.c>
  Header unset X-Powered-By

#redirect to custom error page(s)
ErrorDocument 404 /~jason/404.html

#redirects and aliases for mapping older files to current files
Redirect 301 "/~jason/about.php" "/~jason/about.html"
Redirect 301 "/~jason/contact.php" "/~jason/contact.html"
Redirect 301 "/~jason/files.php" "/~jason/code.html"
Redirect 301 "/~jason/index.php" "/~jason/index.html"
Redirect 301 "/~jason/index.php" ""
Redirect 301 "/~jason/metadata.php" "/~jason/metadata.html"
Redirect 301 "/~jason/portfolio.php" "/~jason/resume.html"
Redirect 301 "/~jason/resume.php" "/~jason/resume.html"
Redirect 301 "/~jason/sandbox.php" "/~jason/code.html"
Redirect 301 "/~jason/talks.php" "/~jason/talks.html"
#RedirectMatch 301 "/home/jason/public_html/files/search-ux/(.*).html" ""

#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]

  #redirect from the `http://` to the `https://` version of the URL.
  RewriteCond %{HTTPS} !=on
  #RewriteRule ^(.*)$ https://%{HTTP_HOST}/~jason/$1 [R=301,L]
  #RewriteRule ^(/~jason|index.html|about.html|code.html|talks.html)$ https://%{HTTP_HOST}/~jason/$1 [R=301,L]
  RewriteRule ^(index.html|about.html|code.html|contact.html|search.html|sitemap.html|talks.html)$ https://%{HTTP_HOST}/~jason/$1 [R=301,L]

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