Remove .html extension from url using web.config only for urls that have .html and not home page

Viewed 460

I have a Plesk account for my website hosting. I don't know anything about web.config files but I am trying to remove .HTML extensions from my URLs. I tried a solution (written later in the post), but it worked perfectly for all URLs but the home page. My home page shows the following error:

Server Error in '/' Application.

Runtime Error

(There is much more text in the error above, but I am trying to keep the question as brief as possible)

When I use www.xyz.com it shows the error. When using www.xyz.index.html, it works fine but the URL I see then becomes www.xyz.index, which is unpleasant to look at. Please refer to this post below and help me with a solution if you can!

Remove HTML extension with web config permanently

Code that is written as the best answer to the post above and also the one I am using:

<configuration>   
    <system.webServer>   
        <rewrite>
            <rules>
                <rule name="Hide .html ext">
                    <match ignoreCase="true" url="^(.*)"/>
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                        <add input="{REQUEST_FILENAME}.html" matchType="IsFile"/>
                    </conditions>
                    <action type="Rewrite" url="{R:0}.html"/>
                </rule>
                <rule name="Redirecting .html ext" stopProcessing="true">
                    <match url="^(.*).html"/>
                    <conditions logicalGrouping="MatchAny">
                        <add input="{URL}" pattern="(.*).html"/>
                    </conditions>
                    <action type="Redirect" url="{R:1}"/>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
1 Answers

Ah, I see what's wrong. It's either you forgot to put a /, or because it is a folder, or it is because you used many domains.

Related