2012-12-13 64 views
0

我對我的網站使用url重寫。我在IIS上做了設置,它在服務器上工作。但它在本地主機上不起作用。這很正常,因爲在我的項目文件中沒有帶重新編址的頁面。我怎麼解決這個問題?我在開發項目時使用cassini服務器。我應該在我的電腦中使用本地IIS嗎?你可以在這裏看到我的url重寫web.config文件中的角色:Url重寫在IIS上工作,但不在localhost中

<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> 
+0

相關:http://stackoverflow.com/q/2708187/1001985,http://stackoverflow.com/q/963545/1001985 – McGarnagle

回答

3

爲什麼不使用Url路由呢? 它是更好的方法

+0

感謝我的兄弟。它效果更好:) – cagin

0

是的,你必須在本地計算機上使用添加/刪除Windows組件安裝IIS。

確保在安裝本地IIS後啓用「URL重寫模塊」。

0

您需要添加否定條件<add input="{HTTP_HOST}" pattern="localhost" negate="true" /> 以便URL重寫器忽略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> 
相關問題