2016-04-03 87 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>