Html 在windows服务器中隐藏/删除url扩展

Html 在windows服务器中隐藏/删除url扩展,html,.htaccess,iis,Html,.htaccess,Iis,我读到了。htaccess不像godaddy那样在windows服务器上工作。因此,要隐藏或删除URL上的.php和.html等扩展名,可以通过使用以下代码创建一个web.config文件来实现: <configuration> <system.webServer> <rewrite> <rules> <rule name="RewriteHTM

我读到了。htaccess不像godaddy那样在windows服务器上工作。因此,要隐藏或删除URL上的.php和.html等扩展名,可以通过使用以下代码创建一个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>
我试图创建web.config文件,并用代码将其保存在index.php所在的位置,但什么也没发生。。我用这样的方法测试了它

<ul>
  <li>
    <a  href="attackontitan-3">Attack on Titan Episode 3</a>
  </li>
</ul> with a href of "attackontitan-3"

我希望url不是

使用“重写”添加扩展名,如下所示:

<rule name="rewritephp">
       <!--Removes the .aspx extension for all pages.-->
       <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}.php" />
     </rule> 
或者,本教程很好地解释了如何使用IIS

您需要添加重写和重定向规则。以下内容将重定向并重写page.php,使其仅限于页面。如果您想对html执行相同的操作,只需添加这些规则

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>
      <rewrite>
         <rules>

            <!-- Remove the existing rules just incase we already defined them -->
            <remove name="RedirectPhpExtensions" />
            <remove name="RewritePhpExtensions" />

            <!-- Add a rule to redirect x.php pages to just x -->
            <rule name="RedirectPhpExtensions" enabled="true" stopProcessing="true">
               <match url="(.*)\.php$" />
               <action type="Redirect" url="{R:1}" redirectType="Permanent" />
            </rule>

            <!-- Add a rule to rewrite the x pages to x.php behind the scene -->
            <rule name="RewritePhpExtensions" enabled="true" stopProcessing="true">
               <match url="(.*)" negate="false" />
               <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}.php" />
            </rule>

         </rules>
      </rewrite>
   </system.webServer>
</configuration>
将此web.config放在域的根目录中

然后,您需要重新启动godaddy站点上的应用程序池:

Web托管>管理>IIS管理>回收应用程序池按钮