2012-12-13 63 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> 
相关问题