【问题标题】:ASP.Net URL Rewrite module Javascript CSS images not showingASP.Net URL 重写模块 Javascript CSS 图像未显示
【发布时间】:2016-12-15 09:13:52
【问题描述】:

我想在 ASP.Net 中使用 Intelligencia.UrlRewriter.RewriterHttpModule 进行 URL 重写,这是我在 web.config 中的以下配置

>  <configSections>
>     <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler,
> Intelligencia.UrlRewriter" />   </configSections>

在 system.web 中

 <httpModules>
      <add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter" />
    </httpModules>

我想要以下类型的网址

site.com/home site.com/contact site.com/info site.com/page/innerpage site.com/in/info

为此我分别写了以下规则

<system.webServer>    
    <rewrite>
      <rules>
        <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
          <match url="^Home$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="\.aspx$"  />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="Default.aspx" />
        </rule>
        <rule name="RewriteUserFriendlyURL2" stopProcessing="true">
          <match url="^contact$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="contact.aspx" />
        </rule>
        <rule name="RewriteUserFriendlyURL3" stopProcessing="true">
          <match url="^([^/]+)/?$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="info.aspx?keyword={R:1}" />
        </rule>
        <rule name="Rewrite to page.aspx">
          <match url="^pages/([^/]+)" />
          <action type="Rewrite" url="page.aspx?page={R:1}" />
        </rule>
        <rule name="Rewrite to info.aspx">
          <match url="([_0-9a-z-]+)/([_0-9a-z-]+)" />
          <action type="Rewrite" url="info.aspx?keyword2={R:1}&amp;keyword={R:2}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  <rewriter>

  </rewriter>

一切正常,但如果使用我习惯获取的最后一条规则并且 CSS / javascript 停止工作,我尝试了许多解决方案来解决 css/javascript/image 规则的暗示但没有奏效。

site.com/in/info

 <rule name="Rewrite to info.aspx">
              <match url="([_0-9a-z-]+)/([_0-9a-z-]+)" />
              <action type="Rewrite" url="info.aspx?keyword2={R:1}&amp;keyword={R:2}" />
            </rule>

【问题讨论】:

    标签: c# asp.net url-rewriting web-config url-rewrite-module


    【解决方案1】:

    试试&lt;match url="^([_0-9a-z-]+)/([_0-9a-z-]+)$" /&gt;

    而且我通常会添加一个角色来重写每个页面,这样你就不需要在 url 中使用 .aspx。所以你可以写 www.domain.com/home 代替 www.domain.com/home.aspx,www.domain.com/subpage/contact 代替 www.domain.com/subpage/contact.aspx 等等。

    <rule name="no_aspx" stopProcessing="true">
      <match url="^([a-z0-9/]+)$" ignoreCase="true"/>
      <action type="Rewrite" url="{R:1}.aspx"/>
    </rule>
    

    【讨论】:

    • 我做了改变,但同样没有改变
    猜你喜欢
    • 2010-11-10
    • 2011-07-31
    • 2012-10-04
    • 2010-09-26
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 2016-11-07
    • 2014-03-23
    相关资源
    最近更新 更多