Redirect URL http to https for one site web.config not redirecting

Discussion forum for Enterprise Edition.
Post Reply
tomk
Posts: 8
Joined: Fri Dec 08, 2017 4:50 pm

Redirect URL http to https for one site web.config not redirecting

Post by tomk »

Currently Running Enterprise 10.20

I have multiple sites each with it's own IP.
I'm having issues with trying to get a redirect for one the sites that require SSL to go from http to https.

The mail webpage works if someone accesses the site either by http or https directly. SSL works and the cert is valid, it just won't redirect if someone goes to the http, they have to manually go to https://xxx

One thing I did notice, when someone connects to https://mail.mysite.com, the URL changes to https://mail.mysite.com/Mondo/lang/sys/login.aspx

If I login to the standard http://mail.mysite.com the URL stays at http://mail.mysite.com

Here's my web.confg info. I've run tests with the IIS rewrite tool, and it appears to pass all tests. Basically I have it so if the user goes to "webmail.mysite.com" or "mail.mysite.com" it will redirect to https://mail.mysite.com

This is located right above the </system.webServer> in file location: C:\Program Files (x86)\Mail Enable\Bin\NetWebMail which in IIS is used by site MailEnable WebMail.

<rewrite>
<rules>
<rule name="Redirect to SSL mail.mysite.com" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="(.+)\.mysite\.com" />
</conditions>
<action type="Redirect" url="https://mail.mysite.com" />
</rule>
</rules>
</rewrite>

Windows 2016 w/IIS 10
Mailenable is the only thing on it
I have also uninstalled and re-installed the Rewrite URL module 2

Any assistance is greatly appreciated!

tomk
Posts: 8
Joined: Fri Dec 08, 2017 4:50 pm

Re: Redirect URL http to https for one site web.config not redirecting

Post by tomk »

I've figured out my problem and just would like to share my resolution.

The issue that was stopping it from working is in IIS the bindings under MailEnable WebMail.

By default there was the generic host built by MailEnable with hostname MEWebMail.localhost IP 127.0.0.1 on port 80.
I added 443 for "mail.mysite.com" to IP XX.XX.XX.XX which allowed direct access to https: But I also had to add another host entry for port 80 for the name hostname and same IP.
After that, restarted the web, and works like a charm. Since I have some users that may use the sub domain "mail" or "webmail" I added webmail on port 80 as well, and that redirects to the https "mail.mysite.com" with a valid cert using the above web.config entry.

...Phew. Done.

kiamori
Posts: 329
Joined: Wed Nov 04, 2009 1:39 am
Contact:

Re: Redirect URL http to https for one site web.config not redirecting

Post by kiamori »

You can also configure a dedicated IIS host to run rules using a global.asax file. Something like:

<script language="C#" runat="server">
protected void Application_BeginRequest(Object sender, EventArgs e) {
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().Replace("http://","https://"));
}
}
</script>

or

<script language="C#" runat="server">
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://somedomain.tld"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().Replace("http://somedomain.tld","https://somedomain.tld"));
}

}
</script>

tomk
Posts: 8
Joined: Fri Dec 08, 2017 4:50 pm

Re: Redirect URL http to https for one site web.config not redirecting

Post by tomk »

:D Nice.. Will have to tinker and try the script method too. Thanks!

dcol
Posts: 237
Joined: Fri May 26, 2017 11:25 pm

Re: Redirect URL http to https for one site web.config not redirecting

Post by dcol »

One problem is ME loads a new web.config every time ME does an update which deletes any rewrite rules.

Post Reply