Ali Imran
Ali Imran

Reputation: 686

redirect url from web.config file not working properly

I want to remove my html extension but failed when going with in the directory. link1 of my site working properply but other directory links are not working properly. link2

i want to remove html extension at the end this link

http://mremind.com/products-services/credentialing.html

but after my rewrite

http://mremind.com/products-services/credentialing/ which is not working.

In stackover flow other question i found the solution of my problem but its not working properly.

my solution in web.config file is

<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>

Upvotes: 1

Views: 645

Answers (1)

VDWWD
VDWWD

Reputation: 35564

I think what you want needs another rewrite rule. You redirect from credentialing.html to credentialing, but that file does not exist so you are probably getting a 404. What you need is a rule that adds the .html extension again as a rewrite so IIS can find the file again.

<rule name="No html ext" stopProcessing="true">
  <match url="^([a-z0-9-_/]+)$" ignoreCase="true" />
  <action type="Rewrite" url="{R:1}.html" />
</rule>

Upvotes: 1

Related Questions