2016-04-03 86 views
0

我在這裏有一個.htaccess文件,我需要將其轉換爲用於Azure的web.config。這裏是htaccess文件:將.htacess轉換爲適用於Azure的web.config

Options +FollowSymlinks 
Options -Multiviews 
ErrorDocument 404 /error-404 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [NC,L] 

我已經將其轉換爲web.config文件,但它不起作用。它只是拋出404錯誤未找到。這裏是web.config:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <rule name="rule 1C" stopProcessing="true"> 
        <match url="!.*\.php$" ignoreCase="true" /> 
        <action type="Rewrite" url="/%{REQUEST_FILENAME}.php". /> 
       </rule> 
      </rules> 
     </rewrite> 
     <defaultDocument> 
      <files> 
       <add value="test.php" /> 
      </files> 
     </defaultDocument> 
    </system.webServer> 
</configuration> 

有關此文件的一切工作,除了重寫。只需要幫助讓頁面在Azure中沒有.php文件擴展名的情況下顯示即可。

回答

0

對於ErrorDocument 404 /error-404,請參閱下文。

<system.webServer> 
    <httpErrors> 
     <remove statusCode="404" /> 
     <error statusCode="404" path="/error-404" responseMode="ExecuteURL"/> 
    </httpErrors> 
</system.webServer> 

重寫網址,請看下面。

<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <rule name="rule 1C" stopProcessing="true"> 
        <match url="!.*\.php$" /> 
         <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>