已将CakePHP移至Azure应用服务,重写不起作用

798qvoo8  于 2023-10-20  发布在  PHP
关注(0)|答案(2)|浏览(142)

将我的CakePHP v2.2应用程序从Linux服务器复制到Azure App Service进行开发/测试。我知道.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. websites在那里。我错过了什么?

\中的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>

\app\中的web.config

<?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>

\app\webroot\中的web.config

<?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>
14ifxucb

14ifxucb1#

修复了!再次找到这篇文章,只更新了\的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>
xdyibdwo

xdyibdwo2#

如果有人在寻找

Cakephp 4x / Azure Web App / nginx解决方案。

上下文- nginx不会尊重.htaccess,所以我们必须使用nginx配置才能使其工作。下面的链接解释了如何准确地做到这一点(但等待,catch隐藏在行的深处......)https://azureossd.github.io/2021/09/02/php-8-rewrite-rule/
现在,如果你按照上面的方法去做,并期望它会起作用,它不会。接下来是“抓住”的部分。Cakephp的结构使得public目录Map到/webroot。因此,请确保更改原始配置中的以下行(即/home/site/default
root /home/site/wwwroot;

root /home/site/wwwroot/webroot;
.你的Cakephp应用程序应该像预期的那样工作。
编码愉快!

相关问题