11

I have created a basic aurelia app starting from this repo and I was trying to get rid of the # (hashtag) in the URL bar.

I have 2 projects, one running WebApi on a machine and one running an empty web project (not MVC) on another machine. On the official documentation website it only says how to configure your routes but my project is not MVC oriented.

How can I configure the IIS server from Web.config in a sense that when I access http://localhost/home it should start the aurelia framework rather than the 404 not found page?

Matt McCabe
  • 2,986
  • 2
  • 22
  • 29

1 Answers1

16

I'm using the Azure which needed a web.config to handle non hash routing correctly, it just redirects all routes into the index.html which contains the aurelia app. Without it (or a similar technique) it was giving 404s.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>
     <rewrite>
             <rules>
                 <remove name="redirect all requests" />
                 <rule name="redirect all requests" stopProcessing="true">
                     <match url="^(.*)$" ignoreCase="false" />
                     <conditions logicalGrouping="MatchAll">
                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                     </conditions>
                     <action type="Rewrite" url="index.html" appendQueryString="true" />
                 </rule>
             </rules>
         </rewrite>
    </system.webServer>
</configuration>

Hope this helps.

Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
Matt McCabe
  • 2,986
  • 2
  • 22
  • 29
  • Thank you. I ended up using something similar :) – Laurentiu Stamate Aug 20 '15 at 13:30
  • Hey Matt, where do you put this `web.config`? I've added mine inside de `wwwroot` folder but I still get 404's – Sergi Papaseit Jan 14 '17 at 19:26
  • @SergiPapaseit that's exactly where I put it, the only time I got 404s was with a type of file that azure doesn't handle by default, like woff or json files. – Matt McCabe Jan 15 '17 at 20:21
  • Tip: you need to have the [IIS URL Rewrite extension](https://www.iis.net/downloads/microsoft/url-rewrite) installed on your Windows server for this to take effect. – Juliën Jul 18 '18 at 11:36