use*_*350 7 php .htaccess rewrite web-config azure
我正在Azure上部署站点,我正在尝试为该站点编写重写规则.
我有以下代码,它的工作原理:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Sendy all" stopProcessing="true">
<match url="^(.+?)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
<rule name="Sendy all" stopProcessing="true">
<match url="^api/(.+?)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但是当我在rules标签中添加以下代码时,我收到错误消息The page cannot be displayed because an internal server error has occurred.为什么?
<rule name="Sendy all" stopProcessing="true">
<match url="^api/(.+?)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
Run Code Online (Sandbox Code Playgroud)
我认为第一版不会起作用。第一版的第二条规则与第二版相同。
您的问题是,规则具有相同的名称 attribute Sendy all。这在 Web Config 中是非法的。重命名一条规则。
另请看一下这个节点(这有利于调试):
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
确保这是web.config. 500.52然后您将获得带有详细描述的错误代码,该错误代码指示了此错误。
在问题旁边,我不明白你在尝试什么。考虑将请求发送给您的 PHP 索引:
<rule name="Sendy all" stopProcessing="true">
<match url="^api/(.+?)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?api=1&request={R:1}" appendQueryString="true" />
</rule>
Run Code Online (Sandbox Code Playgroud)
如果你打电话,website.tld/api/IBar/DoFoo你可以写:
$isApi = isset($_GET['api']); //Was the API Rule Affected?
$request = isset($_GET['request']) ? $_GET['request'] : ''; //"IBar/DoFoo"
Run Code Online (Sandbox Code Playgroud)
如果您不提取详细信息并将它们作为参数提供,则整个 Url Rewrite 事情就没有意义。
| 归档时间: |
|
| 查看次数: |
789 次 |
| 最近记录: |