Search code examples
c#asp.net-coreweb

The page isn’t redirecting properly


I used RewriteOptions to add "/" to end all urls, but when publishing to the iis server I get a "page does not redirect correctly" error.

i using this

var options = new RewriteOptions() //add '/' to end of url
        .AddRedirect("(.*[^/])$", "$1/")
        .AddRedirectToHttpsPermanent();
            app.UseRewriter(options);

Solution

  • Can you suggest a suitable pattern?

    Well, assuming you have already installed URL Rewrite Modulefrom the below official site. Here is the reference for you.

    enter image description here

    Configure URL Rewrite Pattern and Rules:

    As, so far your requirement is to add additional slash / of your website, Thus,you can set this (.*[^/])$ pattern on your URL Rewrite module in IIS as below:

    enter image description here

    Steps for configuration:

    1. Select your site in IIS
    2. Double Click on URL Rewrite under HTTP Features Table
    3. Click On Add Rules(s) top right
    4. Select Append Or remove the trainin slash symbol
    5. Select Appended if does not exist from the dropdown
    6. Click OK

    Note: You can customize your rules as well. If you encounter any concern on this you can have a look below screen capture how to do it.

    Output: enter image description here

    If you still need more further assistance, you could have look on our official document here