简体   繁体   English

ASP.NET IIS7的永久301重定向

[英]Permanent 301 redirect for ASP.NET IIS7

Im trying to figure out how to setup a 301 permanent redirect for a website that is placed on a Microsoft-IIS/7.0 type server. 我试图弄清楚如何为放置在Microsoft-IIS / 7.0类型服务器上的网站设置301永久重定向。 So let's say I have domain www.A.com and I want to redirect this to www.B.com I could use something like the following in my web.config file: 假设我有一个域名www.A.com,并且我想将其重定向到www.B.com,我可以在web.config文件中使用类似以下内容的东西:

<configuration>
<system.webServer>
<rewrite>
   <rules>
      <rule name="Redirect to WWW" stopProcessing="true">
        <match url="A.com" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^www.B.com$" />
   </conditions>
   <action type="Redirect" url="http://www.B.com/{R:0}"
        redirectType="Permanent" />
   </rule>
 </rules>
</rewrite>
</system.webServer>
</configuration>

When placing the web.config in the root directory, the server responds: 将web.config放在根目录中时,服务器将响应:

403 - Forbidden: Access is denied. 403-禁止访问:拒绝访问。 You do not have permission to view this directory or page using the credentials that you supplied. 您无权使用您提供的凭据查看此目录或页面。

Any suggestion why this 403 error is given? 任何建议为什么会给出此403错误?

Thanks in advance. 提前致谢。

If you are getting a 403 error with a plain (default) web.config and totally vanilla Default.aspx, then there is a configuration problem with IIS. 如果使用普通(默认)web.config和完全香草的Default.aspx收到403错误,则IIS存在配置问题。 Most likely the app pool does not have rights to the base folder for the website. 应用程序池很可能无权访问网站的基本文件夹。 Sounds like you're in a hosted situation so contact the system administrator. 听起来您处于托管状态,请与系统管理员联系。

This should work and also be much simpler. 这应该有效并且也更简单。 You don't need URL rewriting, just HTTP redirect. 您不需要URL重写,只需HTTP重定向。

As for the 403, does the IIS application pool have read access to the folder at the root of your site? 至于403,IIS应用程序池是否对站点根目录的文件夹具有读取权限?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="true" destination="www.B.com" httpResponseStatus="Permanent" />
    </system.webServer>
</configuration>

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

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