2015-02-11 85 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管理>回收應用程序池按鈕