我正在我的项目中实现URL重写.我使用URL Rewrite添加了从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>
Run Code Online (Sandbox Code Playgroud)
但问题是我已经编写了删除扩展名的规则,即.aspx,我希望我的网址看起来像
http://localhost:58370/URLRedirect/Default.
Run Code Online (Sandbox Code Playgroud)
但现在它正在显示它http://localhost:58370/URLRedirect/
如何解决这个问题.....
最后,我能够解决从文件中删除.aspx扩展名的问题.我希望我的网址看起来像:
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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5497 次 |
| 最近记录: |