簡體   English   中英

ASP.Net URL重寫模塊Javascript CSS圖像未顯示

[英]ASP.Net URL Rewrite module Javascript CSS images not showing

我想用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>

嘗試<match url="^([_0-9a-z-]+)/([_0-9a-z-]+)$" />

而且我通常會添加一個角色來重寫每個頁面,以便您在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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM