【问题标题】:URL rewriting gives a 500 Server error with my web.config fileURL 重写导致我的 web.config 文件出现 500 服务器错误
【发布时间】:2013-01-15 19:42:03
【问题描述】:

我已使用以下代码尝试为我的网站搜索结果实现干净的 URL。但是,当我将它实现到我的 web.config 文件中并将其上传到我的站点时,我收到了服务器 500 错误。我做错了什么?

我正在尝试清理一些 URL,请参阅下面的链接:

mydomain.com/dentists/zipcode/18954/us/

mydomain.com/dentists/name/18954/us/the-persons-name/

mydomain.com/dentists/phone/18954/us/3215558888

mydomain.com/dentists/details/person-company-goes-here/

这就是我的 web.config 文件中的内容...

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite to store_locator_results.php">
                    <match url="^dentists/zipcode/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/" />
                    <action type="Rewrite" url="store_locator_results.php?lat={R:1}&amp;lng={R:2}&amp;postcode={R:3}&amp;countryIso={R:4}&amp;businessname={R:5}" />
                </rule>
            </rules>
            <rules>
                <rule name="Rewrite to store_locator_results_by_name.php">
                    <match url="^dentists/name/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/" />
                    <action type="Rewrite" url="store_locator_results_by_name.php?lat={R:1}&amp;lng={R:2}&amp;postcode={R:3}&amp;countryIso={R:4}&amp;lastname={R:5}&amp;businessname={R:6}" />
                </rule>
            </rules>
            <rules>
                <rule name="Rewrite to store_locator_results_by_phone.php">
                    <match url="^dentists/phone/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/" />
                    <action type="Rewrite" url="store_locator_results_by_phone.php?lat={R:1}&amp;lng={R:2}&amp;postcode={R:3}&amp;countryIso={R:4}&amp;phone={R:5}" />
                </rule>
                <rule name="Rewrite to store_locator_results.php">
                    <match url="^dentists/details/([0-9]+)/" />
                    <action type="Rewrite" url="store_info.php?store={R:1}" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="Rewrite to clean URL" preCondition="IsHTML">
                    <action type="Rewrite" value="/dentists/zipcode/{R:3}/{R:4}" />
                    <action type="Rewrite" value="/dentists/name/{R:3}/{R:4}/{R:5}/" />
                    <action type="Rewrite" value="/dentists/phone/{R:3}/{R:4}/{R:5}/" />
                    <action type="Rewrite" value="/dentists/details/{R:1}/" />
                </rule>
                <preConditions>
                    <preCondition name="IsHTML">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

【问题讨论】:

    标签: php iis-7 url-rewriting web-config rewrite


    【解决方案1】:

    web.configsystem.webServer 之前和configuration 标记内添加以下行。

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

    这将覆盖 IIS 中的 mod_rewrite 规则。

    【讨论】:

    • 这给了我一个错误:“必须在'section'标签上指定'type'属性。”我应该使用什么类型?
    • @SsjCosty 我一直在研究这个问题。我认为您需要使用新语法。我希望this link 中的默认配置部分可能会有所帮助。
    猜你喜欢
    • 2015-11-25
    • 2012-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多