【问题标题】:Moved CakePHP to Azure App Service, rewrites aren't working将 CakePHP 移至 Azure App Service,重写不起作用
【发布时间】:2017-10-08 11:56:57
【问题描述】:

将我的 CakePHP v2.2 应用程序从 linux 服务器复制到 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.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>

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

【问题讨论】:

    标签: cakephp mod-rewrite cakephp-2.0


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-10
      • 2020-04-26
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 2013-12-16
      • 2015-09-17
      • 1970-01-01
      相关资源
      最近更新 更多