Remove Trailing Slash From the URL(从 URL 中删除尾部斜杠)
问题描述
我想将abc.aspx/"重定向到abc.aspx".这怎么办?
I want to redirect "abc.aspx/" to "abc.aspx". How can this be done?
当请求的页面以/"结尾时页面被破坏.如何处理此类请求?有什么重写规则可以添加到web.config文件中吗?
Page gets broken when requested page ends with '/'. How to handle such type of requests? Is there any rewriting rule that can be added into web.config file?
推荐答案
在你的 web.config 中,在 system.webServer 下,添加
In your web.config, under the system.webServer, add
<rewrite>
<rules>
<!--To always remove trailing slash from the URL-->
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
一些问题
在您的开发环境中,如果您在 Visual Studio Development Sever 下运行您的网站,您将无法看到此功能正在运行.您需要将应用程序配置为至少在 IIS Express 下运行.
In your development environment, if you run your web site under Visual Studio Development Sever, you won't be able to see this feature working. You will need to configure your application to run under at least IIS Express.
当您部署网站并发现此功能在您的生产服务器上不起作用时,那是因为您错过了某些配置.常见的错误之一是将 overrideModeDefault 属性设置为 Deny 以将 下的规则设置为 applicationHost.config 文件.
When you deploy your web site and see that this feature is not working on your production server, it will be because you miss configured something. One of the common mistakes is having overrideModeDefault attribute set to Deny for rules under <sectionGroup name="rewrite"> inside your applicationHost.config file.
如果您在共享主机环境中并且发现此功能不起作用,请询问您的提供商是否已授予您配置此部分的权限.
If you are on a shared hosting environment and you see that this feature is not working, ask your provider if they have given you the permission of configuring this part.
来源:http://www.tugberkugurlu.com/archive/remove-trailing-slash-from-the-urls-of-your-asp-net-web-site-with-iis-7-url-rewrite-module
这篇关于从 URL 中删除尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 URL 中删除尾部斜杠
基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
