statiqdev / Website

Code for the statiq.dev website, built with Statiq.
MIT License
21 stars 34 forks source link

URL Rewrite rule fails when using cleanblog theme #32

Open darrelmiller opened 2 years ago

darrelmiller commented 2 years ago

https://github.com/statiqdev/statiqdev.github.io/blob/91f859804f6eafdc1ebe0a574d65f7c25dca58bf/input/web/deployment/azure-app-service.md#L50

As the cleanblog created summary HTML files with the same name as folders, the above redirect rules failed to rewrite to the posts.html and the tags.html. I'm not sure if the right option is to change the cleanblog theme to create the posts.html as index.html in the posts folder and tags folder, but for the moment, the redirects below solved my problems.

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="html">
          <match url="(.+)/?" />
          <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
          </conditions> 
          <action type="Rewrite" url="{R:1}.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
daveaglick commented 2 years ago

That's some impressive redirect hacking!

image

😬

So I've confirmed the behavior (not much doubt there) and I'm conflicted on where the problem is and what should be done to fix it:

darrelmiller commented 2 years ago

I don't know what the answer is. The rewrite rules do seem to be working for me at the moment but I have not tested extensively. I do think that having index.html in the posts folder rather than a posts.html and a posts folder would likely be a more resilient design for cleanblog. On the other hand, this is a funky issue caused by IIS insisting on putting a trailing slash on paths that point to folders even before the rewrite rules hit. I think it would probably be sufficient to have an issue in the cleanblog repo that warns people of the issue when hosting on IIS and suggests the alternative rewrite rules.

daveaglick commented 2 years ago

Cool - that's how I'll proceed for now if for no other reason than it's easy and I've been trying to focus on shipping Statiq Docs with what little time I've got. I'll leave this issue open to remind me to add something to the main docs as well.

I also opened issues for changing the CleanBlog files and implementing an analyzer for this situation - I think both are good ideas as time allows.

Thanks!

chucker commented 2 years ago

The rewrite rules do seem to be working for me at the moment but I have not tested extensively.

Hm, interesting. On my machine (Windows Server 2019 / IIS 10), your changed web.config showed the same phenomenon for me. Individual posts work, but the tags and posts URLs throw a 404.

Shoving the posts.html/tags.html inside their folder as index.html each did the trick.

darrelmiller commented 2 years ago

Yeah, I also discovered the issue with tags. Although for some strange reason posts are working for me.