0

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...

koffik
  • 1
  • 1
  • Did you include the trailing slash when testing (I mean did you use `http://mycompany.com/autodiscover/` and not `http://mycompany.com/autodiscover`)? It is a common error not to include it, which in your case would cause the "autodiscover" rules to never match. – Lacek May 22 '19 at 10:48
  • Yes I did, I even used a Outlook as AutoDiscover client do test the full URL it checks: `https://mycompany.com.com/autodiscover/autodiscover.xml` From the logs It clearly gives a 301 first, gets redirected to www where it gets a 404 after the second attempt. I'd like to directly give a 404 instead of the client trying generating more requests. – koffik May 22 '19 at 14:10

0 Answers0