Search code examples
iisweb-configiis-manager

web.config: URL rewrite to remove directory


So currently I've got the URL websitename.com/posts/post

and I would like to change it to websitename.com/post

I've been trying now for 3 days with no luck. Seen loads of stuff for .htaccess but not much for web.config

Apologies in advance as I'm sure I'm asking a really dumb question,

Thank you!


Solution

  • Maybe this is what you want. Put it in the root directory of your website. You could also change Rewrite to Redirect there.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="posts" patternSyntax="ExactMatch">
                        <match url="/posts/post" />
                        <action type="Rewrite" url="/post" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>