I have been stuck on this issue and have not been able to find a solution. I am using Apache 2.4.41.
I am attempting to create a RewriteRule on a site if the currently viewing folder has any files inside with a certain file extension (for this example, I will be using txt). I have Directory Indexing enabled so when a user clicks on a folder with one of these files inside, it'll rewrite using the rule I have set.
My issue is that I am not sure how I would detect this. I have looked into using a RewriteCond but I was unable to get it working and couldn't figure out what was going wrong.
RewriteCond %{REQUEST_FILENAME}/^(*.txt)$ -f
It does not error out or return a 500, but also does not perform what I am wanting at all.
I also tried using an If directive:
<If "-f %{REQUEST_URI} . '/*\.(txt)$'">
# Do stuff
</If>
I am very certain I am using that entirely wrong, however I was unable to figure out if there was a correct way as I could not find any examples.
My goal is to have the directory and any subdirectory of it follow this setting I have set for it.
/thing1/test.txt <- YES
/thing1/subthing1/ <- YES
/thing2/txt.data <- NO
/thing2/subthing2/ <- NO
If the file in the directory doesn't exist, it shouldn't matter. Due to the way I have my apache configured, it would redirect to the 404 ErrorDocument.
The actual use and plan for this is to allow older virtual world software to connect to a world on my webserver through HTTP and explore, since a majority of older software do not support HTTPS. I run a small archival project, and it would make it a lot easier if I only had to force HTTP for it to work when necessary.
How can I achieve this?