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

查看:131
本文介绍了从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.

当您部署网站并看到此功能在生产服务器上不起作用时,这是因为您错过了一些配置.常见错误之一是将< sectionGroup name ="rewrite"> 下的规则的 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.

来源: 查看全文

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