Last active
March 8, 2024 08:49
-
-
Save shanept/53614431eb016ec8fbd82df33ae4e2eb to your computer and use it in GitHub Desktop.
Outputs headers for files based upon exclusion from an extension list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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