Why does this regex misfire on css? - regex

I'd like any files not matching my extension list to be forced to download and so I added
<FilesMatch "(?i)(?<!\.css|\.eot|\.flv|\.gif|\.html|\.ico|\.jpeg|\.jpg|\.js|\.json|\.m4v|\.mov|\.mp3|\.ogg|\.pdf|\.png|\.svg|\.ttf|\.txt|\.webm|\.webp|\.woff|\.xhtml|\.xml)$">
Header set Content-Disposition attachment
</FilesMatch>
to .htaccess but I am getting the header on CSS files as well. Running https://regex101.com/r/M26y55/4 says "Your regular expression does not match the subject string."

Related

Exclude a folder from step Get file names when include subfolders = Y in PENTAHO

I am trying to get the name of all .xlsx file in multiple subfolders with a root directory. I am wanting to exclude one or more subdirectories.
I have tried
File/Directory
Wildcard (RegExp)
Exclude wildcard
Required
Include subfolders
\\peace\vol2\Temp\Test
.*.xlsx
.*\bkup
N
Y
.+bkup.+
I want all files in all of the subfolders except for any files in the \\peace\vol2\Temp\Test\bkup subdfolder. I am using the Get file name step and it is working fine for the wildcard but the exclude is not excluding the directory.
I know I am close but can someone help with right syntax?

Including multiple .txt files into httpd.conf using regex?

I want to be able to include multiple virtualhost files into httpd.conf. I know that it's possible to include one using something like:
include virtualhost-1.txt
However, I want to be able to import all virtualhost files within a certain directory, without needing to hardcode the include statements. Is there an appropriate command/syntax for this? I know the directory and have a suitable regular expression:
^.+-[0-9]+\.txt
The syntax of the Include directive is the following:
Include file-path|directory-path|wildcard
You can do for example:
Include /usr/local/apache2/conf/vhosts/dom1-*.conf
to include all configuration starting with dom1- from the directory /usr/local/apache2/conf/vhosts/. Note that you can use wildcards but you cannnot use a full regex.

htaccess match specific file types in root directory

I would like to match specific file types within the root directory the website. This htaccess file also sits in the root directly.
I've got this so far:
<FilesMatch "\.(php|png|ico)$">
Allow from all
</FilesMatch>
None of my attempts to restrict the matches to the same directory have been successful. I'm sure it's something super simple.
Try to do it this way:
<FilesMatch ".*\.(php|png|ico)$">
Allow from all
</FilesMatch>
I found out that only looks at the file name. It does not look at the directory part of the filename at all.
There is a but your not able to use it in a htacces file.
So the only way is through a Rewrite Rule. Something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "^(subdir/).*/.*\.(html|json)$" "-" [PT,L]
# -- Deny Everything Not Matched Above -- #
RewriteRule "/*" "-" [F]
</IfModlue>
The above will only allow html or json files to be accessed in a second (or greater) sub-directory within a directory called subdir in the same folder as the htaccess file. Everything else will be forbidden. Assuming mod_rewrite is installed. The files will also be treated as files, which is not the default behavior for a rewrite rule.

How to hgignore all files of a particular extension except in one directory and its subdirectories?

I would like to use the .hgignore file of Mercurial to ignore all files with file extension .tex, except those .tex files in one particular directory and whatever subdirectory of this directory.
I presume syntax: regexp will be required for this.
A brief explanation of the particular regular expression used, would also be very welcome, so that we can all learn a bit here.
Let's say you want to exclude the directory named exclude. The following regex would then match all files that end in .tex unless exclude/ comes somewhere before that:
^(?!.*\bexclude/).*\.tex$

.htaccess caching with FilesMatch

I need to make browser caching with htaccess file.
From this question I found out how to add extensions to htaccess file.
<FilesMatch "\.(js|jpeg|jpg)$">
But I need to add extensions. But exclude some of the files.
I found something like this from this question
<FilesMatch ^((myfile|myfile2)\.js$|myphoto\.jpe?g)$>
Add all js and jpeg files except "myfile.js", "myfile2.js", "myphoto.jpg"
How can I do this?
Thank you
Try this
<FilesMatch "((?<!myfile|myfile2)\.js|(?<!myphoto).jpe?g)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
This will match all js and jpeg files except myfile.js, myfile2.js, and myphoto.jpeg using negative lookahead/lookbehind. Kind of ugly but I couldn't find a nice way to do this.
You can then have a separate files match for only those files and set a different header:
<FilesMatch "((myfile|myfile2)\.js|myphoto\.jpe?g)$">
Header set Cache-Control "max-age=3600, public"
</FilesMatch>