Question

I use url rewriting for my web site. I did settings on IIS and it works on server. But it doesn't work on localhost. It is normal because there is no page with rewrited url in my project files. How can I solve this problem? I use cassini server when I develop my project. Should I use local IIS in my computer? You can see here my url rewriting roles in web.config file:

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
        <rewrite>
            <outboundRules>
                <rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^(.*/)ProductDetail\.aspx\?prid=([^=&amp;]+)&amp;(?:amp;)?product=([^=&amp;]+)$" />
                    <action type="Rewrite" value="{R:1}ProductDetail/{R:2}/{R:3}/" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
            <rules>
                <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^urun/([^/]+)/([^/]+)/?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="ProductDetail.aspx?prid={R:1}&amp;product={R:2}" />
                </rule>

            </rules>
        </rewrite>
        <urlCompression doDynamicCompression="false" />
  </system.webServer>
Was it helpful?

Solution

Why don't use Url Routing instead? it's better way

OTHER TIPS

Yes, you have to install IIS on your local computer using Add/Remove Windows Components.

Make sure also to enable the "URL Rewrite module" within your local IIS, once it's installed.

You need to add a negate condition <add input="{HTTP_HOST}" pattern="localhost" negate="true" /> so the URL rewriter ignores any requests on localhost.

<rewrite>
  <rules>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
    </rule>
  </rules>
</rewrite>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top