301使用单独的重定向文件重定向(在azure上)

时间:2016-10-17 15:42:23

标签: azure redirect iis web-config

我尝试使用Url Rewrite将旧网站网址重定向到新网站,并将网址放在单独的文件中。我理想地想要捕获所有http和https请求。这就是我在web.config中的内容。

<rewrite>
<rewriteMaps configSource="rewritemaps.config" />
    <rules>
        <rule name="Redirect oldsite.com to newsite.com" stopProcessing="true">
        <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www.oldsite.com$" />
            </conditions>
            <action type="Redirect" url="https://www.newsite.com" redirectType="Permanent" appendQueryString="false" />
        </rule>
  </rules>
</rewrite>

在我的rewritemaps.config文件中

<rewriteMaps>
<rewriteMap name="Redirects">
  <add key="/~woodburningstove/index.php/contacts/" value="/ContactUs" />
  <add key="/about-us" value="/about-us-2" />
  <add key="/blog" value="/blog" />
  <add key="/brands" value="/manufacturer/all" />
  <add key="/brands/herald" value="/herald-stoves" />
  <add key="/brands/stovax" value="/stovax-stoves" />
  <add key="/brands/town-country" value="/town-country-fires"/>
  <add key="/brands/warmglow" value="/warmglow-stoves"/>
  <add key="/brands/warmglow/warmglow-4-cast-iron-stove-flat-black-paint-finish" value="/warmglow-4-black-2"/>
  <add key="/brands/warmglow/warmglow-7-cast-iron-stove-flat-black-paint-finish" value="/warmglow-7-cast-iron-black"/>
  <add key="/brands/warmglow/warmglow-7-cast-iron-stove-flat-ivory-enamel" value="/warmglow-7-cast-iron-ivory-enamel"/>
  <add key="/brands/warmglow/warmglow-7-cast-iron-stove-flat-metallic-black-enamel" value="/warmglow-7-cast-iron-metallic-black-enamel"/>
  <add key="/brands/warmglow/warmglow-7-cast-iron-stove-flat-metallic-black-enamel" value="/warmglow-7-cast-iron-metallic-black-enamel"/>
</rewriteMap>
</rewriteMaps>

但是我一直得到&#34;由于发生了内部服务器错误,因此无法显示页面&#34;但我无法发现我做错了什么!?

2 个答案:

答案 0 :(得分:1)

我的rewritemaps.config文件中有重复的条目。以下列出了两次:

<add key="/brands/warmglow/warmglow-7-cast-iron-stove-flat-metallic-black-enamel" value="/warmglow-7-cast-iron-metallic-black-enamel"/>
<add key="/brands/warmglow/warmglow-7-cast-iron-stove-flat-metallic-black-enamel" value="/warmglow-7-cast-iron-metallic-black-enamel"/>

答案 1 :(得分:0)

是由于你的正则表达式吗?

旧:

<add input="{HTTP_HOST}" pattern="^www.oldsite.com$" />

新:

<add input="{HTTP_HOST}" pattern="^www\.oldsite\.com$" />

否则我建议关闭自定义错误或进行一些远程调试。 https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-troubleshoot-visual-studio/