【问题标题】:GoDaddy Web.Config URL Rewrite not workingGoDaddy Web.Config URL 重写不起作用
【发布时间】:2013-01-27 21:35:10
【问题描述】:

我有这个网络配置:

<?xml version="1.0"?>

<configuration>
  <configSections>
  </configSections>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <!--maxRequestLength = maximum upload size =- 4096KB = 4MB-->
    <httpRuntime maxRequestLength="409600000"/>
  </system.web>

  <system.webServer>
    <rewrite>
      <rules>
        <!--The following rule will only work when published-->
        <rule name="Construction" stopProcessing="true">
          <match url="Construction\.aspx" negate="true"/>
          <conditions>
            <!-- dont ignore my own ip -->
            <add input="{REMOTE_ADDR}" pattern="XXX.XXX.XXX.XXX" negate="true"/>
          </conditions>
          <action type="Redirect" url="Construction.aspx" redirectType="Found"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

</configuration>

它在我本地机器上的 IIS 上工作,但在其他机器上,我最终遇到以下问题:

  1. 包含rewrite 部分时出现500 错误。当我删除它时,一切正常。
  2. 我无法将调试输出打印到屏幕上。

这有什么问题?

【问题讨论】:

  • 您的 500 响应代码是否还有其他说明?
  • 不,没什么。直到我删除了我的 webconfig 的 部分,默认的 500 页面才被替换为服务器错误的调试跟踪:/

标签: .net debugging url-rewriting web-config


【解决方案1】:

您可以尝试以下配置。这具有重写块,它将到达文件夹的请求重定向到 index.php 页面,并且还将输出详细错误而不是自定义/通用错误页面。这是在托管 IIS 8.5 的 Godaddy 窗口上测试的。希望这会有所帮助!

<configuration>
 <system.webServer>
    <httpErrors errorMode="Detailed"></httpErrors>
    <asp scriptErrorSentToBrowser="true"></asp>
    <rewrite>
     <rules>
      <rule name="your rule" stopProcessing="true">
       <match url="(.*)$"  ignoreCase="false" />
       <conditions>        
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />        
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />        
       </conditions> 
       <action type="Rewrite" url="index.php?request={R:1}"  appendQueryString="true" />
      </rule>
     </rules>
    </rewrite>
  </system.webServer>
  <system.web>
    <customErrors mode="Off"></customErrors>
    <compilation debug="true"></compilation>
  </system.web>
</configuration>

【讨论】:

    【解决方案2】:

    我只是添加到标签:

    <configSections>
          <sectionGroup name="system.webServer">
               <sectionGroup name="rewrite">
                    <section name="rewriteMaps" overrideModeDefault="Allow" />
                    <section name="rules" overrideModeDefault="Allow" />
               </sectionGroup>
         </sectionGroup>
    </configSections>
    

    所以现在它不会出错,但它也不会读取重写

    【讨论】:

      【解决方案3】:

      我已按照@CohenA Detailed 500 error message, ASP + IIS 7.5 的回答来帮助了解 500 个错误的完整详细信息。我只是把它注释掉,直到我遇到错误,所以我不必记住它。


      您是否针对 ReWrite 问题查看了 this answer?不确定你想用 ReWrite 做什么,但也许你想使用规则 #2

      或者,您是否缺少重定向上的前导 /?

      【讨论】:

      • 必须在代码
      • 这可能是我打赌重定向的前导斜线!我会在今天晚些时候检查并回来。
      • ... 不走运。即使只是在 下添加一个空的 也会导致 500 错误。
      • 我也试过“~/Construction.aspx”和“../Construction.aspx”。也许我没有在 IIS 上安装重写模块? GoDaddy 声称它是默认安装的。
      • 尝试删除条件?也许它是区分大小写的?我有一个带有星号 * 通配符的重定向,但文档并未表明这在您的实例中应该很重要。
      【解决方案4】:

      在我使用rewrite 的情况下,我不会在匹配的 url 属性中转义句点。你试过&lt;match url="^Construction.aspx$" negate="true"/&gt;吗?

      诚然,这有点牵强,因为我已经有一段时间没有为此深入研究文档了。

      【讨论】:

      • 不,没什么。直到我删除了我的 webconfig 的 部分,默认的 500 页面才被替换为服务器错误的调试跟踪:/
      猜你喜欢
      • 2021-08-25
      • 2013-12-23
      • 1970-01-01
      • 2018-05-20
      • 2017-10-06
      • 2012-08-05
      • 2023-03-27
      • 1970-01-01
      • 2016-12-18
      相关资源
      最近更新 更多