antivinegar
antivinegar

Reputation: 447

URL rewriting gives a 500 Server error with my web.config file

I've used the code below to try and achieve clean URLs for my site search results. However, when I implemented it into my web.config file and upload it to my site I get a Server 500 Error. What did I do wrong?

There are a few URLS that I'm trying to clean, see links below:

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/

This is what I have in my web.config file...

<?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>

Upvotes: 4

Views: 11796

Answers (1)

Hbksagar
Hbksagar

Reputation: 547

Add following lines in web.config before system.webServer and within the configuration tag.

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

This will overwrite mod_rewrite rule in IIS.

Upvotes: 4

Related Questions