-1

I am losing my mind over IIS 10 putting a trailing slash whenever i target a subfolder on my web server that contains an index file. Not only it always redirects via 301 to a trailing slash, my SEO rankings are hurt so badly that i can't rank up anywhere. I've read all the famous answers everywhere (including the famous rule described here) and nothing helps.

Example:

I have this structure

root

  • sets (subfolder)
    • index.php
    • test.php

It is so bad that even my homepage (my / root) gets redirected to 301 from website.com to website.com/

When i go to website.com/sets, i intentionally don't link to website.com/sets/index.php, i get the trailing slash. When i go to website.com/test.php (or even website.com/test with rewriting the .php) i am fine. No trailing slash.

Here is my entire rules in my web.config. I've tried disabling the "Remove PHP" rule, I still get the trailing slash. I've moved them around - nothing, i've tried converting some htaccess examples into web.config - nothing. I am despearate at this point.

    <rules>
       <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAny">
             <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
       </rule>
       <rule name="Redirect naked domain to www" enabled="true" stopProcessing="true">
             <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
             <add input="{HTTP_HOST}" negate="true" pattern="^www\." />
          </conditions>
          <action type="Redirect" url="https://www.{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
       </rule>
       <rule name="Remove PHP" enabled="true" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions logicalGrouping="MatchAll">
             <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
             <add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
          </conditions>
          <action type="Rewrite" url="{R:1}.php" />
       </rule>
          <!--To always remove trailing slash from the URL - Does not work!!!!-->
       <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> 
       <rule name="Prevent image hotlinking" enabled="false"> <!-- turned off for now -->
          <match url=".*\.(gif|jpg|png)$" />
          <conditions>
          <add input="{HTTP_REFERER}" pattern="^$" negate="true" />
          <add input="{HTTP_REFERER}" pattern="^https://www.website\.com/.*$" negate="true" />
          </conditions>
          <action type="Rewrite" url="/images/say_no_to_hotlinking.jpg" />
       </rule>
    </rules>

Edit:

I've read this - https://developers.google.com/search/blog/2010/04/to-slash-or-not-to-slash. If i understood it correctly - if one 301 to the other and the other returns 200 - it's fine .... hmmm .. So i don't have to change anything? it is fine as it is?

Djongov
  • 195
  • 2
  • 13

1 Answers1

-1

Please take the following steps to see if this helps:

  1. Open IIS Manager and navigate to the level you want to manage.
  2. In Features View, double-click HTTP Redirect.
  3. On the HTTP Redirect page, select Redirect requests to this destination.
  4. In the Actions pane, click Apply.

More information you can refer to this link: https://learn.microsoft.com/en-us/iis/configuration/system.webserver/httpredirect/

samwu
  • 3,857
  • 3
  • 11
  • 25