我正在我的项目中实现URL重写。我添加了使用URL重写从IIS进行重写的规则。下面是添加规则的我的web.config文件的代码:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="URLRedirect" stopProcessing="true">
<match url="^([a-z0-9/]+).aspx$" />
<action type="Redirect" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
但是问题是我写了只删除扩展名即.aspx的规则,我希望我的URL看起来像
http://localhost:58370/URLRedirect/Default.
但是现在它显示为“http://localhost:58370/URLRedirect/
如何解决此问题.....
最终,我能够解决从文件中删除.aspx扩展名的问题。我希望我的URL看起来像:http://localhost:58370/ShowPage
代替http://localhost:58370/ShowPage.aspx
1)我在名为ShowPage的文件夹中添加了ShowPage.aspx页面。2)以下是我添加到我的web.config文件中的规则:
<rewrite>
<rules>
<clear />
<rule name="Redirect to clean URL" enabled="true" stopProcessing="true">
<match url="^([a-z0-9/]+).aspx$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="RewriteASPX" enabled="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
</rewrite>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句