2015-02-11 62 views
1

我读到.htaccess不能在像godaddy这样的Windows服务器上工作。因此,要隐藏或删除喜欢的扩展名为.php和.html的网址,你可以用下面的代码创建一个web.config文件实现这一点:隐藏/删除Windows服务器的URL扩展

<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" 

我想要的网址是http://mysite/watching/attack%20on%20titan/attackontitan-3http://mysite/watching/attack%20on%20titan/attackontitan-3.php

回答

0

使用重写添加扩展名,如:

<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做什么时做得很好。

http://atlantawebsites.blogspot.com/2010/06/vanity-urls-with-godaddy-hosting-using.html

0

您需要添加一个RewriteRedirect规则。以下将重定向并重写page.phppage。如果你想为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的网站:

虚拟主机>管理> IIS管理>回收应用程序池按钮