1

Hi have two problems using IIS rewrite and redirect rules in front of a web page hosted on GitHub Pages.

Rewrite to GitHub Page

Update: Everything worked perfectly. As described later in this question, it was GitHub Pages that did the redirect to the canonical URL. Adding a rewrite appending the missing trailing slash before hitting GitHub Pages fixed it:

<rule name="Add Trailing Slash" stopProcessing="true">
  <match url=".*[^/]$" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{REQUEST_FILENAME}" pattern=".+?\.\w+$" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>
  <action type="Redirect" url="{ToLower:{R:0}}/" />
</rule>

The site is hosted on GitHub Pages and available here: http://elmahio.github.io/blog/.

In order to rewrite requests to my proxy, I have added the following rewrite rule:

<rule name="Proxy" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_URI}" negate="true" pattern="^(.*)/.well-known/(.*)$"/>
  </conditions>
  <action type="Rewrite" url="http://elmahio.github.io/blog/{R:1}" />
</rule>

The rewrite rule works like a charm. But if anyone forget the trailing slash to an URL, it seems to redirect to the GitHub Page version. Example:

https://blog.elmah.io/great-dot-net-conferences-to-attend redirects to http:// elmahio.github.io/blog/great-dot-net-conferences-to-attend/

I can see that GitHub Pages automatically append the trailing slash if not there. This might even be the main problem, since my proxy rewrite to the GitHub one and then redirect to append the trailing slash.

Any ideas to how to fix this? Maybe add a redirect rule in my proxy, appending that slash before rewriting to GitHub Pages?

Redirect to HTTPS

Update: Removing my custom redirect rule and enabling HTTPS Only on the Custom domain view on Azure, fixed this problem

I want all requests made to a non-https URL, redirected to HTTPS. I have added a redirect rule to web.config like this:

<rule name="RedirectToHTTPS" stopProcessing="true">
  <match url="(.*)"/>
  <conditions>
    <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
  </conditions>
  <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent"/>
</rule>

The rewrite rule works fine on URL's containing a path. Example:

http://blog.elmah.io/great-dot-net-conferences-to-attend/ redirects to https://blog.elmah.io/great-dot-net-conferences-to-attend/

But when visiting the front page (http://blog.elmah.io/ or http://blog.elmah.io) without HTTPS, I am not redirected to the HTTPS URL.

What could go wrong here?

ThomasArdal
  • 4,999
  • 4
  • 33
  • 73

1 Answers1

1

All your rewrites are correct. Most probably issue exists because of GitHub pages. Try to do the following:

1) Create a rule to append trailing slash. You can find the example of rewrite rule in this thread IIS URL Rewrite: Add trailing slash except for .html and .aspx

2) Instead of using rewrite rule for redirect to HTTPS, you can enable HTTPS Only on the Custom domain view on Azure

Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36