How to exclude my admin directories from hiding .html in its urls

Rich K 21 Reputation points
2022-06-28T22:49:15.237+00:00

I'm using this to remove the .html in urls on my website:

    <rewrite>  
        <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>  
            <rule name="Redirecting .html ext" enabled="true" stopProcessing="true">  
                <match url="^(.*).html" />  
                <conditions logicalGrouping="MatchAny">  
                    <add input="{URL}" pattern="^(.*)\.html$" />  
                </conditions>  
                <serverVariables />  
                <action type="Redirect" url="{R:1}" />  
            </rule>  
        </rules>  
    </rewrite>  

I need to omit my --admin directory and all its subdirectories from having html removed

Tried a few things from similar questions but no luck.

I want to exclude www.website.com/--admin from having any of it's html extensions removed.

I use www.website.com/--admin/page.html?id=new and similar and if html is removed it all fails

Thanks for any suggestions.

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

Accepted answer
  1. Yurong Dai-MSFT 2,846 Reputation points Microsoft External Staff
    2022-06-29T04:08:45.183+00:00

    Hi @Rich K ,

    According to your description, I think you want to hide .html in the URL, but don't want to hide .html in the URL containing the admin directory and all its subdirectories, because this will give an error.
    I have a method that requires some modification to your rewrite rule named Redirecting .html ext. In the matching URL, use regular expressions to exclude specific strings "admin".

    <match url="^(.*).html" /> is changed to <match url="^(?!admin)(.*).html" / >  
    

    This worked for me, you can try it.


    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 related email notification for this thread.

    Best regards,
    Yurong Dai

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Rich K 21 Reputation points
    2022-06-29T10:48:58.283+00:00

    That slight change works.

    What's sorta odd but a-ok is when I go to my admin page for the 1st time
    www.website.com/--admin/index.html

    The .html is still omitted, but only on that 1st index page

    All other links like www.website.com/--admin/page.html?id=new
    show the .html and anything I want done regarding id= or action= on my admin pages works just fine.

    THANKS

    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.