将我的 CakePHP v2.2 应用程序从 Linux 服务器复制到 Azure 应用服务以进行开发/测试。我知道 .htaccess 不起作用,所以我在每个文件夹中添加了一个 web.config
\
& \app\
& \app\webroot\
。网站的根部工作,主页加载,从 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.configs 就在那里。我错过了什么?
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 4x / Azure Web App / nginx 解决方案。
背景- nginx 不会尊重 .htaccess,因此我们必须使用 nginx 配置来使其正常工作。以下链接解释了具体如何执行此操作(但是等等,问题隐藏在行深处......) https://azureossd.github.io/2021/09/02/php-8-rewrite-rule/
现在,如果您按照上述步骤操作并期望它会起作用,那么它不会起作用。这是“捕获”部分。 Cakephp 的结构使得公共目录映射到
/webroot
。因此,请确保更改原始配置中的以下行(即/home/site/default
)
root /home/site/wwwroot;
到
root /home/site/wwwroot/webroot;
...您的 Cakephp 应用程序应该按预期工作。
编码快乐!