2017-06-20 45 views
0

问题:如何在Azure Web Apps上添加重写配置?

我试图从具有nginx的自身的VPS是一个Azure的Web应用程序迁移PHP的Web应用程序。在NGINX配置中,还有一些需要迁移的重写规则。现在,该应用程序正在运行,除了重写之外。

我做

什么。所以,给我创建了一个名为applicationHost.xdt文件,并将其添加到/site文件夹中的重写。我测试了新的.xdt正在通过添加一个超时规则来读取,后来我发现它已被插入主配置文件/local/Config/applicationhost.config。然而,我的规则不存在,它根本不工作。

我也试过在名为web.config/wwwroot文件夹下添加下面的文件。

applicationHost.xdt:

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <system.applicationHost> 
    <webLimits xdt:Transform="SetAttributes(connectionTimeout)" 
       connectionTimeout="00:00:30" /> 
    </system.applicationHost> 

    <location path="{main_location_for_web_app}" xdt:Transform="InsertIfMissing" > 

    <system.webServer xdt:Transform="InsertIfMissing"> 
     <rewrite xdt:Transform="InsertIfMissing"> 
     <rules xdt:Transform="InsertIfMissing" lockElements="clear"> 
      <rule name="amr" enabled="true" stopProcessing="true" lockItem="true"> 
      <match url="{my app url}/introduction.php" /> 
      <action type="Redirect" url="{my app url}/reset.php" appendQueryString="true" redirectType="Permanent" /> 
      </rule> 
     </rules> 
     </rewrite> 
    </system.webServer> 
     </location> 

</configuration> 

我是相当新的这一切,但它是我需要做的任务。我很感激,如果有人能告诉我我做错了什么或调试这个最好的方法。

回答

0

把这个放在web.config文件夹下的/wwwroot文件夹下。这会将用户从introduction.php重定向到reset.php。我测试了它,它应该工作。

<?xml version="1.0" encoding="UTF-8" ?> 
<configuration> 
    <system.webServer>  
     <rewrite> 
      <rules> 
       <rule name="amr" enabled="true" stopProcessing="true" lockItem="true"> 
        <match url="introduction.php" /> 
        <action type="Redirect" url="reset.php" appendQueryString="true" redirectType="Permanent" /> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 
</configuration> 

详情请参阅Creating Rewrite Rules for the URL Rewrite Module


我也想你applicationHost.xdt更改以下行后:

<location path="{main_location_for_web_app}" xdt:Transform="InsertIfMissing" > 

到:

<location path="%XDT_SITENAME%" xdt:Transform="InsertIfMissing" xdt:Locator="Match(path)"> 

并重新启动应用程序服务,然后我得到了它的工作。

+0

谢谢你。我仍然试图让它工作。我使用了你提供的示例,而不是'introduction.php',我使用'。*'不适合我。调试它的最佳方法是什么?我怎么能100%确定'web.config'文件正在被读取。再次感谢。 –

+1

发现我的错误。我的代码在'/ wwwroot/html'而不是'/ wwwroot'中,因此'web.config'文件需要位于'/ wwwroot/html /'中,因为它是Web应用程序的新根。 –