LocationMatch Regular Expression Behavior
I am trying to set a bunch of url based rules in Apache using LocationMatch and the regex seems to behave in a way I don't understand.
I've tried looking for the documentation, but I'm not very clear on what WRT is for my problem ... and other questions / answers around interwebs.
Here is my Location directive and a general example of the structure of my LocationMatch directives:
<Location />
Header set X-Intelligence "CatchAll"
</Location>
<LocationMatch "\.(pdf)$">
Header set X-Intelligence "pdf1"
</LocationMatch>
- These directives are located inside the virtual host using ssl.
- I am not using any other Location or LocationMatch directives in other configurations.
- The LocationMatch directives all appear after my Location CatchAll directive.
- Everything works fine when I only use the directive
<Location />
.
I noticed some differences between the regex used here and the regex that I have experience with.
- Using start and end codes does not work.
- Using end modifier tags like / i / g doesn't work.
- Other behavioral differences below
I've tried many different things, but here are some examples of my results:
1.
<LocationMatch "(?i)\.(pdf)$">
Header set X-Intelligence "pdf1"
</LocationMatch>
- The above seems to match all .pdf and .PDF urls.
However:
<LocationMatch "\.(pdf)$">
Header set X-Intelligence "pdf1"
</LocationMatch>
- Doesn't match urls of .pdf extension.
- .pdfs don't end up in CatchAll (404 not found displayed).
- .PDF (capitals) do end up in CatchAll.
...
2. Not like this:
<LocationMatch "\.(docx?)$">
Header set X-Intelligence "doc2"
</LocationMatch>
- The above matches my .docx urls.
However:
<LocationMatch "\.(doc)$">
Header set X-Intelligence "doc2"
</LocationMatch>
<LocationMatch "\.(docx)$">
Header set X-Intelligence "doc22"
</LocationMatch>
- The above do not match .docx urls.
- Doesn't hit CatchAll (404 not found).
- I tried reordering the order and it still gives the same results.
Not sure what is going on, but the behavior is completely not what I expect. Anyone have any ideas on what I might be doing wrong or what I am not understanding?
Open all suggestions to make this question better. Thank.
source to share
No one has answered this question yet
Check out similar questions: