将 CakePHP 移至 Azure App Service,重写不起作用
Moved CakePHP to Azure App Service, rewrites aren't working
已将我的 CakePHP v2.2 应用从 linux 服务器复制到 dev/testing 的 Azure 应用服务。我知道 .htaccess 不起作用,所以我在每个文件夹 \
& \app\
& \app\webroot\
中添加了一个 web.config。站点的根有效,主页加载,读取数据表单 SQL,CSS 和 JS 加载。 CSS 文件托管在 \app\webroot\css
中,但通过 example.com\css\file.css
访问,所以我假设某种重写正在工作。
问题是在转到页面时,即 example.com/about
,我收到错误 The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
我在这里看到了大部分关于在 IIS 上托管此内容的帖子,我想我的 web.config 也在那里。我错过了什么?
web.config 在 \
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rule1A" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="app/webroot/" />
</rule>
<rule name="rule2A" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
web.config 在 \app\
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="rule 1A" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="webroot/" />
</rule>
<rule name="rule 2A" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="webroot/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
web.config 在 \app\webroot\
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="CakePHP" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
已修复!再次找到这篇文章,并仅更新了 \
处的 web.config 并删除了其他两个位置的 web.config。很有魅力!
https://book.cakephp.org/2.0/en/installation/url-rewriting.html#url-rewrites-on-iis7-windows-hosts
web.config 在 \
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite requests to test.php"
stopProcessing="true">
<match url="^test.php(.*)$" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/test.php{R:1}" />
</rule>
<rule name="Exclude direct access to app/webroot/*"
stopProcessing="true">
<match url="^app/webroot/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
stopProcessing="true">
<match url="^(img|css|files|js|favicon.ico)(.*)$" />
<action type="Rewrite" url="app/webroot/{R:1}{R:2}"
appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php"
stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php"
appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
已将我的 CakePHP v2.2 应用从 linux 服务器复制到 dev/testing 的 Azure 应用服务。我知道 .htaccess 不起作用,所以我在每个文件夹 \
& \app\
& \app\webroot\
中添加了一个 web.config。站点的根有效,主页加载,读取数据表单 SQL,CSS 和 JS 加载。 CSS 文件托管在 \app\webroot\css
中,但通过 example.com\css\file.css
访问,所以我假设某种重写正在工作。
问题是在转到页面时,即 example.com/about
,我收到错误 The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
我在这里看到了大部分关于在 IIS 上托管此内容的帖子,我想我的 web.config 也在那里。我错过了什么?
web.config 在 \
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rule1A" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="app/webroot/" />
</rule>
<rule name="rule2A" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
web.config 在 \app\
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="rule 1A" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="webroot/" />
</rule>
<rule name="rule 2A" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="webroot/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
web.config 在 \app\webroot\
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="CakePHP" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
已修复!再次找到这篇文章,并仅更新了 \
处的 web.config 并删除了其他两个位置的 web.config。很有魅力!
https://book.cakephp.org/2.0/en/installation/url-rewriting.html#url-rewrites-on-iis7-windows-hosts
web.config 在 \
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite requests to test.php"
stopProcessing="true">
<match url="^test.php(.*)$" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/test.php{R:1}" />
</rule>
<rule name="Exclude direct access to app/webroot/*"
stopProcessing="true">
<match url="^app/webroot/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
stopProcessing="true">
<match url="^(img|css|files|js|favicon.ico)(.*)$" />
<action type="Rewrite" url="app/webroot/{R:1}{R:2}"
appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php"
stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php"
appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>