Redirect Autodiscover URL’s using .htaccess

There are several ways an emailclient can perform autodiscover to detect its settings, however, most clients do not implement all methods. One example is the iPhone, which works as follows:

E-mail address entered: bob@example.com

  1. Connect to https://example.com/Autodiscover/Autodiscover.xml
  2. Connect to http://example.com/Autodiscover/Autodiscover.xml

This works if the root of your e-mail hosting domain points to an Exchange Client Access Server. However, most of the time it doesn’t. A common case would be that the website is hosted elsewhere on for example an Apache HTTPD server. Of course, when the iDumbPhone connects to either URL’s above, it fails because the file doesn’t exist.

If both methods fail, the iPhone bugs out and asks the user to manually enter the server address, username, domain, etc… Well they won’t be entering it, as IT guy, you will be. What you can do is redirect the iPhone’s request to your mailserver using a HTTP 302 Temporary Redirect status code. To do so:

Create a file called .htaccess in your DocumentRoot with the following content:

RedirectMatch 302 (?i)^/Autodiscover/(.*)$ https://yourcas.example.com/Autodiscover/$1

Adjust where necessary. If your Client Access Server is mail.example.com:

RedirectMatch 302 (?i)^/Autodiscover/(.*)$ https://mail.example.com/Autodiscover/$1

This will cause all requests to http://example.com/Autodiscover/Autodiscover.xml to be redirected to https://mail.example.com/Autodiscover/Autodiscover.xml, thus allowing iPhones to correctly autodiscover all server information needed to configure the account.

Hint: to make this work, your webhosting provider must support .htaccess files and has not blocked the RedirectMatch directive

Hint2: if autodiscover still fails and you are sure the iPhones are being correctly redirected, set the user’s UPN to loginname@example.com (example.com being the e-mail domain being used – resolvable on the internet) and have your users enter that as “E-mail Address” when the iPhone asks for it.

References

Advertisements

3 thoughts on “Redirect Autodiscover URL’s using .htaccess

  1. This is the one and only method I found so far to let autodiscover work using SRV records *and* a domain that is not the base one (for iPhone and Apple devices).
    Long story short: you’re a lifesaver!

  2. I found using mod_rewrite preferable because it can handle multiple case conditions depending on the autodiscover client.

    RewriteEngine On
    RewriteRule “^Autodiscover/(.*)$” “http://autodiscover.%{HTTP_HOST}/Autodiscover/$1” [R=301,L,NC]

    Assuming autodiscover.domain.com is set up (which it should be) this takes all autodiscover URLs and redirects them to the proper destination.

    • the quotation marks, may or may not need to be there, but if copying from here, you will need to make sure to fix them so they are standard quotes, not Fancy quotation marks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s