Mr T
Mr T

Reputation: 1000

Add .html to url in Azure web.config rewrite

I am looking to use the sub-page link for a website on Azure, for example:

Html file mysubpage.html placed in the wwwroot directory in Azure. I wish to be able to access this page by typing mysite.com/mysubpage into the web browser. However, when I visit this url I get the output "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

I understand that I need to do this with a web.config file in the wwwroot directory, but am unsure as to what contents the web.config file needs to contain?

I currently have the following:

<?xml version="1.0" ?> <configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite Rule">
                    <match url=".*" />
                    <conditions>
                        <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
                    </conditions>
                    <action type="Rewrite" url="{C:1}" />
                </rule>
                <rule name="Remove html Extension" stopProcessing="true">
                    <match url="^(.+)\.html$" />
                    <action type="Redirect" url="{R:1}" redirectType="Permanent" />
                </rule>
            </rules>
            <rewriteMaps>
                <rewriteMap name="StaticRewrites" defaultValue="">
                    <add key="/mysubpage" value="/mysubpage.html" />
                </rewriteMap>
            </rewriteMaps>
        </rewrite>
    </system.webServer> </configuration>

Upvotes: 2

Views: 644

Answers (1)

Mr T
Mr T

Reputation: 1000

Solved the issue. The following worked which removed the removal of the html extension:

<?xml version="1.0" ?> <configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite Rule">
                    <match url=".*" />
                    <conditions>
                        <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
                    </conditions>
                    <action type="Rewrite" url="{C:1}" />
                </rule>
            </rules>
            <rewriteMaps>
                <rewriteMap name="StaticRewrites" defaultValue="">
                    <add key="/mysubpage" value="/mysubpage.html" />
                </rewriteMap>
            </rewriteMaps>
        </rewrite>
    </system.webServer> </configuration>

I understand that it you want to re-route numerous urls you can do this by adding extra lines with add as follows:

                    <add key="/mysubpage1" value="/mysubpage1.html" />
                    <add key="/mysubpage2" value="/mysubpage2.html" />

Upvotes: 1

Related Questions