Remove HTML extension with web config permanently

前端 未结 3 946
北海茫月
北海茫月 2020-12-13 22:19

I am trying to remove html extension from pages using web.config. Below is the code i am using in web.config file


  
    

        
相关标签:
3条回答
  • 2020-12-13 22:22

    If you want to do this on a per-website basis using the local IIS server on Windows 10, install the URL Rewrite module and then put this in web.config in the root of your virtual directory:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <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>
        </system.webServer>
    </configuration>
    
    0 讨论(0)
  • 2020-12-13 22:25

    URLRewrite 2.0 rule (insert this part inside system.webServer node) that replaces .html from url:

    <rewrite>
        <rules>
            <rule name="Hide .html ext">
                <match ignoreCase="true" url="^(.*)"/>
                <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>
                <action type="Rewrite" url="{R:0}.html"/>
            </rule>
            <rule name="Redirecting .html ext" stopProcessing="true">
                <match url="^(.*).html"/>
                <conditions logicalGrouping="MatchAny">
                    <add input="{URL}" pattern="(.*).html"/>
                </conditions>
                <action type="Redirect" url="{R:1}"/>
            </rule>
        </rules>
    </rewrite>
    
    0 讨论(0)
  • 2020-12-13 22:42

    I know this is almost a year latter but I'll try. I'm not sure I understand your problem correctly but if I do I just use

        <system.webServer>
         <caching>
          <profiles>
           <remove extension=".php" />
           <remove extension=".html" />
           <add extension=".html" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="23:59:59" varyByQueryString="*" />
           <add extension=".php" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:00:30" varyByQueryString="*" />
                 </profiles>
                 </caching>
                 <directoryBrowse enabled="false" />
                 <defaultDocument>
    

    Then the rest of the closing statements that you are using.

    0 讨论(0)
提交回复
热议问题