简体   繁体   English

web.config:URL重写以删除目录

[英]web.config: URL rewrite to remove directory

So currently I've got the URL websitename.com/posts/post 所以目前我有URL websitename.com/posts/post

and I would like to change it to websitename.com/post 我想将其更改为websitename.com/post

I've been trying now for 3 days with no luck. 我已经尝试了3天,没有运气。 Seen loads of stuff for .htaccess but not much for web.config 看到大量的.htaccess内容,但对于web.config却不多

Apologies in advance as I'm sure I'm asking a really dumb question, 预先道歉,因为我确定我在问一个非常愚蠢的问题,

Thank you! 谢谢!

Maybe this is what you want. 也许这就是您想要的。 Put it in the root directory of your website. 将其放在您网站的根目录中。 You could also change Rewrite to Redirect there. 您也可以在此处将“ Rewrite更改为“ Redirect

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM