【问题标题】:CakePHP 3.0 IIS web.configCakePHP 3.0 IIS web.config
【发布时间】:2015-06-05 22:49:51
【问题描述】:

我所有的图片和 css 网址,或在应用程序前呈现的网址

/app/favicon.ico
/app/img/logo.png
/app/css/styles.css

页面内容渲染良好,只是图像和 css 没有。

我的 web.config 看起来像这样,但似乎对这些 url 没有帮助。因此,它们都导致 404。

<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="Imported Rule 4" stopProcessing="true">
        <match url="^(.*)$" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>
        <action type="Rewrite" url="app/index.php?url={R:1}" appendQueryString="true" />
    </rule>
    <rule name="Exclude direct access to 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="Imported Rule 1" stopProcessing="true">
        <match url="^$" ignoreCase="false" />
        <conditions logicalGrouping="MatchAll">
            <add input="{URL}" pattern="^app/webroot/" ignoreCase="false" negate="true" />
        </conditions>
        <action type="Rewrite" url="app/webroot/" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
        <match url="^(.*)$" ignoreCase="false" />
        <action type="Rewrite" url="app/webroot/{R:1}" />
    </rule>
</rules>

生成的网址应该是

/favicon.ico
/img/logo.png
/css/styles.css

我在 iis 上的目录树是:

www

应用程序

网络根

【问题讨论】:

    标签: php cakephp iis iis-7.5 cakephp-3.0


    【解决方案1】:

    @ADmad 帮我解决了这个问题。事实证明,这与 IIS 中的 web.config 无关。它也不是 CakePHP 3.0 特有的东西。根据 CakePHP IRC,CakePHP 3.x 和 CakePHP 2.x 的路由是完全一样的。这简直就是 IIS PHP 的怪癖。

    解决方案是在你的 config/app.php 中更新 App.base

    'App' => [
        'namespace' => 'App',
        'encoding' => 'UTF-8',
        'base' => '', // default is false
        'dir' => 'src',
        'webroot' => 'webroot',
        'wwwRoot' => WWW_ROOT,
        //'baseUrl' => '/',
        'fullBaseUrl' => false,
        'imageBaseUrl' => 'img/',
        'cssBaseUrl' => 'css/',
        'jsBaseUrl' => 'js/',
        'paths' => [
            'plugins' => [ROOT . DS . 'plugins' . DS],
            'templates' => [APP . 'Template' . DS],
            'locales' => [APP . 'Locale' . DS],
        ],
    ],
    

    @ADmad 说原因是,“因为某些 iis 古怪蛋糕无法正确检测碱基本身:)”

    【讨论】:

      【解决方案2】:

      在根文件夹中创建一个 web.config 文件并粘贴以下行:

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="Exclude direct access to webroot/*"
                        stopProcessing="true">
                          <match url="^webroot/(.*)$" ignoreCase="false" />
                          <action type="None" />
                      </rule>
                      <rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
                        stopProcessing="true">
                          <match url="^(font|img|css|files|js|favicon.ico)(.*)$" />
                          <action type="Rewrite" url="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>
      

      【讨论】:

      • 请不要发布仅代码的答案。也添加一些描述
      • 它不适用于“js/lib/jquery.inputmask/jquery.inputmask.extensions-2.5.0.js”
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      相关资源
      最近更新 更多