URL重写使我的web.config文件出现500 Server错误

时间:2013-01-31 16:18:48

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

我已经使用下面的代码尝试为我的网站搜索结果创建干净的网址。但是,当我将其实现到我的web.config文件并将其上传到我的网站时,我收到了Server 500错误。我做错了什么?

我正在尝试清理一些网址,请参阅以下链接:

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>

1 个答案:

答案 0 :(得分:3)

web.config之前和system.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规则。