如何在Angular中执行301永久重定向

时间:2020-08-02 08:03:21

标签: angular iis

我正在使用angular(version 10)Universal服务于我的Web应用程序,并且我的Web服务器是IIS。 如何执行从该URL:https://myapp.com/a到此URL:https://myapp.com/b的301永久重定向。 我已经尝试过this solution,但无法正常工作

1 个答案:

答案 0 :(得分:1)

使用这样的web.config文件:

    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Angular Routes" stopProcessing="true">
                        <match url=".*NEWPDS.*" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        </conditions>
                         <action type="Rewrite" url="./index.html" />
                    </rule>    

           <rule name="URL1" stopProcessing="true">
                   <match url="^onetoberedirected.html" ignoreCase="true" />
               <action type="Redirect" url="desiredPage" redirectType="Permanent" />
                </rules>
                <outboundRules>    
                </outboundRules>
            </rewrite>
        </system.webServer>
    
</configuration>
相关问题