Asp.net mvc IIS重写甚至重写图像/css/js-导致找不到404

Asp.net mvc IIS重写甚至重写图像/css/js-导致找不到404,asp.net-mvc,iis,url-rewriting,question2answer,Asp.net Mvc,Iis,Url Rewriting,Question2answer,我正试图重写网址,使其搜索引擎友好 www.mydomain.com/qa/213/who-am-i 改写为 www.mydomain.com/qa/?qa=213/who-am-i 下面的代码块可以工作,但问题是页面中的js/css/images URL也会被重写。因此,页面会查找像www.mydomain.com/qa/213/who-am-i/jquery.js这样的文件,这些文件实际上并不存在。因此页面会加载,但是css、.js和图像都不起作用 <rule name="Clean

我正试图重写网址,使其搜索引擎友好

www.mydomain.com/qa/213/who-am-i

改写为

www.mydomain.com/qa/?qa=213/who-am-i

下面的代码块可以工作,但问题是页面中的js/css/images URL也会被重写。因此,页面会查找像www.mydomain.com/qa/213/who-am-i/jquery.js这样的文件,这些文件实际上并不存在。因此页面会加载,但是css、.js和图像都不起作用

 <rule name="CleanRouting" stopProcessing="true">
          <match url="^qa/(.*)/(.*)$" ignoreCase="true" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="qa/?qa={R:1}/{R:2}&amp;{QUERY_STRING}" appendQueryString="false" />
        </rule>


请告诉我如何解决这个问题。我正在使用Asp.Net MVC(如果有必要)。

经过几个小时和几天的时间,我终于找到了正确的IIS重写规则,用于绕过图像/css/js等文件,以便页面正确显示

必须将以下重写规则添加到ASP.Net MVC项目的Web.Config中

<!--Rewrite all paths containing a period like www.conceptworld.com/qa/453/who-am-i/qa-images/search.png to  www.conceptworld.com/qa/qa-images/search.png -->

<rule name="RewriteFileUrls" stopProcessing="true">
          <match url="^qa\/([^\/]*)\/([^\/]*)\/(.*[\.].*)$" ignoreCase="true" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="qa/{R:2}/{R:3}" appendQueryString="false" />
        </rule>

问答基于PHP的解决方案类似于StackOverflow。我已经在Windows系统上安装了IIS+Asp.NETMVC

<!--Rewrites urls like www.conceptworld.com/qa/tags -->

<rule name="RewriteSingleLevelUrls" stopProcessing="true">
          <match url="^qa\/([^\/]*)$" ignoreCase="true" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="qa/?qa={R:1}&amp;{QUERY_STRING}" appendQueryString="false" />
        </rule>

<!--Rewrites urls like www.conceptworld.com/qa/56/who-am-i -->
        <rule name="RewriteTwoLevelUrls" stopProcessing="true">
          <match url="^qa\/([^\/]*\/[^\/]*)$" ignoreCase="true" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="qa/?qa={R:1}&amp;{QUERY_STRING}" appendQueryString="false" />
        </rule>

. 我几乎放弃了,并认为当它安装在Windows(IIS+Asp.NETMVC)上时,在Question2Answer中不可能有相当的SEO友好URL,直到我发现了这个设置。感谢问题2解答开发者:)

转到Admin/Layout并设置基本url,如下所示:

现在,您已经准备好与IIS Asp.Net MVC一起运行Question2Answer

<!--Rewrites urls like www.conceptworld.com/qa/tags -->

<rule name="RewriteSingleLevelUrls" stopProcessing="true">
          <match url="^qa\/([^\/]*)$" ignoreCase="true" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="qa/?qa={R:1}&amp;{QUERY_STRING}" appendQueryString="false" />
        </rule>

<!--Rewrites urls like www.conceptworld.com/qa/56/who-am-i -->
        <rule name="RewriteTwoLevelUrls" stopProcessing="true">
          <match url="^qa\/([^\/]*\/[^\/]*)$" ignoreCase="true" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="qa/?qa={R:1}&amp;{QUERY_STRING}" appendQueryString="false" />
        </rule>