jasonclark/clark-website/master/.htaccess - Htaccess File

jasonclark/clark-website/master/.htaccess

#add handler that allows html, xml, and json to work dynamically as PHP
#https://httpd.apache.org/docs/current/mod/mod_mime.html#addtype
#https://httpd.apache.org/docs/current/mod/mod_mime.html#addhandler
#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
</FilesMatch>

#serve all resources labeled as 'text/html' or 'text/plain' with the media type 'charset' parameter set to UTF-8'
#https://httpd.apache.org/docs/current/mod/core.html#adddefaultcharset
AddDefaultCharset utf-8

#serve correct media type (MIME type) for resources
#https://httpd.apache.org/docs/current/mod/mod_mime.html#addtype
<Files "manifest.json">
AddType application/manifest+json .json
</Files>
<Files "opensearch.xml">
AddType application/opensearchdescription+xml .xml
</Files>
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/vnd.ms-fontobject .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
#https://httpd.apache.org/docs/current/mod/mod_deflate.html
<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/vnd.ms-fontobject" "font/eot" "font/opentype" "font/otf" "font/ttf" "font/x-woff" "image/bmp" "image/jpeg" "image/svg+xml" "image/vnd.microsoft.icon" "image/x-icon" 
</IfModule>

#remove `ETags` as resources are sent with far-future expires headers
#https://developer.yahoo.com/performance/rules.html#etags
#https://tools.ietf.org/html/rfc7232#section-2.3
#`FileETag None` doesn't work in all cases.
<IfModule mod_headers.c>
  Header unset ETag
</IfModule>

FileETag None

#set expires headers to improve caching
#https://httpd.apache.org/docs/current/mod/mod_expires.html
<IfModule mod_headers.c>
  ExpiresActive on
  ExpiresDefault "access plus 1 month"

  #CSS
  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/vnd.microsoft.icon "access plus 1 week"
  ExpiresByType image/x-icon "access plus 1 week"

  #HTML
  ExpiresByType text/html "access plus 0 seconds"

  #JavaScript
  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/vnd.ms-fontobject "access plus 1 month"
  ExpiresByType font/eot "access plus 1 month"

  #OpenType
  ExpiresByType font/opentype "access plus 1 month"

  #TrueType
  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" 
</IfModule>

#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
</IfModule>

#redirect to custom error page(s)
#http://httpd.apache.org/docs/current/custom-error.html
ErrorDocument 404 /~jason/404.html

#redirects and aliases for mapping older files to current files
#https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect
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" "https://www.lib.montana.edu/~jason/"
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" "https://www.lib.montana.edu/~jason/files.html"

#rewrite rules for URLs and directory patterns
#https://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteEngine
#https://httpd.apache.org/docs/current/mod/core.html#options
#https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
#https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions
<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.
  #https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
  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]
</IfModule>

On Github License

Files

Download PDF of Htaccess file
DEFLATE, ENV, HTTP_HOST, HTTPS, REDIRECT_STATUS, REQUEST_FILENAME

Comments

Apache