Skip to content

Instantly share code, notes, and snippets.

@shanept
Last active March 8, 2024 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanept/53614431eb016ec8fbd82df33ae4e2eb to your computer and use it in GitHub Desktop.
Save shanept/53614431eb016ec8fbd82df33ae4e2eb to your computer and use it in GitHub Desktop.
Outputs headers for files based upon exclusion from an extension list
# Outputs headers for files that are not static.
# Using a negative lookahead, we exclude any files that match the list, then apply the headers.
# If you wish to apply headers based on the list, remove the negative lookahead.
<FilesMatch "^(.+\.(?!(?:gif|png|bmp|jpe?g|html?|xml|mp3|mp4|wma|flv|wmv|ogg|avi|docx?|xlsx?|pptx?|txt|pdf|zip|exe|tat|ico|css|js|swf|apk|m3u8|ts|ejs|svg|woff|otf)$)[^\.]+|[^\.]+?)$">
Header set Cache-Control "no-cache"
</FilesMatch>
# Regex works as follows:
#
# ^( # Create matching group, match from start
# .+\. # Greedily consume filename to last dot i.e. "homeage."
# # Look ahead excludes specified extensions from match i.e. gif, png, bmp etc.
# (?!(?:gif|png|bmp|jpe?g|html?|...)$)
# # We have a match, consume extension i.e. "php"
# [^\.]+
# |
# # If we have no extension, just match everything. i.e. /home/
# [^\.]+?
# )$ # Match to end of string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment