I want to respond with 404 for /autodiscover/ on https://mycompany.com as this is the URL Outlook (and other clients using Exchange autodiscover) checks at startup.
What this vHost also does is redirecting everything else from https://mycompany.com to https://www.mycompany.com.
I've tested my rewrite rules with https://htaccess.madewithlove.be/ where it says that my rules should actually yield a 404 directly to any given /autodiscover/ variant I've defined, yet I can clearly see in the logs that what eventually matches is the 301 redirect from non-www to www instead.
RewriteEngine on
RewriteRule ^autodiscover/(.*)$ - [L,R=404]
RewriteRule ^AutoDiscover/(.*)$ - [L,R=404]
RewriteRule ^autoDiscover/(.*)$ - [L,R=404]
RewriteCond %{HTTP_HOST} ^mycompany.com [NC]
RewriteRule ^(.*)$ https://www.mycompany.com/$1 [L,R=301]
I've looked at https://httpd.apache.org/docs/2.4/rewrite/flags.html and the L and as far as I understood the documentation no other rules should be checked when a rule is matched using that flag.
I'm looking for some pointer as to why this does not work as I expect it to after trying out several variants of rewrite rules...