Remove trailing slash from url

I want to redirect "abc.aspx /" to "abc.aspx". How can I do that?

The page is broken when the requested page ends with '/'. How do you handle these types of requests? Is there a rewrite rule that can be added to the web.config file?

+3


source to share


2 answers


In your web.config under 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>

      

Some Gotchas

In your development environment, if you run your website under Visual Studio Development Sever, you won't be able to see this feature. You will need to configure your application to run on at least IIS Express.



When you deploy your website and see that this feature is not working on your production server, it will be because you are missing something. One of the common mistakes is that the attribute is overrideModeDefault

set to Deny

for rules under <sectionGroup name="rewrite">

inside your applicationHost.config file.

If you are in a shared hosting environment and see this feature is not working, please contact your ISP if they have given you permission to configure this part.

Source: http://www.tugberkugurlu.com/archive/remove-trailing-slash-from-the-urls-of-your-asp-net-web-site-with-iis-7-url-rewrite-module

+10


source


You can also refer to this url for more information: Remove trailing slash



+1


source







All Articles