从Windows Server中的URL中删除.html扩展名

ale*_*ara 3 web-hosting iis-8 windows-server-2012

我在GoDaddy上有一个网站,我刚刚意识到他们使用的是Windows服务器,而不是Apache.这意味着使用.htaccess文件不起作用.

我想从所有网站网址中删除.html和.php扩展程序.

基本上,问题是:如何为Windows Server重写(在.htaccess文件中)?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Run Code Online (Sandbox Code Playgroud)

ale*_*ara 10

解决了!

您可以通过使用以下代码创建web.config文件来完成此操作:

<configuration>   
 <system.webServer>   
    <rewrite>          
        <rules>             
            <rule name="RewriteHTML">
              <match url="(.*)" />
                <conditions logicalGrouping="MatchAll">                     
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                     
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />                 
                </conditions>                 <action type="Rewrite" url="{R:1}.html" />             
            </rule>                
        </rules>      
    </rewrite>   
 </system.webServer>  
</configuration>
Run Code Online (Sandbox Code Playgroud)