url-rewrite omit subdirectory

Rich K 21 Reputation points
2022-10-03T20:58:23.75+00:00

I have a subdirectory with html files in it.
domain.com/sub/file.html

I would like to rwerite the url of any files viewed in this one directory to be seen as:
domain.com/file

The following rule works great to hide the .html part in the site in any and all directories visited.

        <rules>  
            <remove name="Redirecting .html ext" />  
            <remove name="Hide .html ext" />  
            <rule name="Hide .html ext" enabled="true">  
                <match url="^(.*)" ignoreCase="true" />  
                <conditions>  
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />  
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />  
                    <add input="{REQUEST_FILENAME}.html" matchType="IsFile" />  
                </conditions>  
                <serverVariables />  
                <action type="Rewrite" url="{R:0}.html" />  
            </rule>	  
        </rules>		  

How would I indicate the directory /sub in a rule and hide it's .html endings?

I use this to match a directory of files to NOT hide the .html part (I need to do that on form input pages)

            <rule name="Redirecting .html ext" enabled="true" stopProcessing="true">  
                <match url="^(?!_-_admin-new)(.*).html" />  
                <conditions logicalGrouping="MatchAny">  
                    <add input="{URL}" pattern="^(.*)\.html$" />  
                </conditions>  
                <serverVariables />  
                <action type="Redirect" url="{R:1}" />  
            </rule>  

Possible?

Windows development | Internet Information Services
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yurong Dai-MSFT 2,846 Reputation points Microsoft External Staff
    2022-10-04T06:11:03.383+00:00

    Hi @Rich K ,

    What you can do with rewrite action is to type domain.com/sub/file in the browser to access domain.com/sub/file.html. But rewrite doesn't change the address in the browser, so if your goal is to remove part of the path from the URL, you can't use the rewrite action.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the email notification for this thread.

    Best regards,
    Yurong Dai

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.