1) 我正在尝试部署到 Azure Web 应用程序。我正在尝试将从 wwwdata 到 wwwdata/app/public/的所有流量写入,这样我就可以保证敏感文件的安全。
2) 我还想要通过删除 .php 或 .html(如果文件存在)来获得漂亮的 URL。
我可以单独实现上述两个功能,但尝试同时实现这两个功能时会遇到问题。我尝试过作为一个文件来定义完整的规则集,也尝试过分成两个文件......
/web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="TransferToPublic" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Rewrite" url="app/public/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
与
/app/public/web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite php" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
<rule name="Rewrite html" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.html" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
但总是收到...
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
非常感谢任何帮助。
最佳答案
根据我的理解,在第一条规则中,您指定了 stopProcessing="true",因此第二条规则不会被处理。我想知道您是否尝试将其设置为 false 或删除 stopProcessing 属性以查看它是否正常工作?我在Azure网站上进行了快速测试:http://testgitproject.azurewebsites.net/example1 & http://testgitproject.azurewebsites.net/example2它似乎按预期工作。如果您有任何进一步的疑虑或者我对您的问题有任何误解,请随时告诉我。
关于php - Mod 将所有文件重写到公共(public)文件夹并剥离 .php、.html(如果文件存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31162279/