从 URL 中删除尾部斜杠 [英] Remove Trailing Slash From the URL

查看:57
本文介绍了从 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 中删除尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆