CakePHP 3.0 IIS web.config

问题描述 投票:0回答:2

所有我的图片和CSS的网址或者使用app进行渲染的网址

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

页面的内容渲染得很好,而不是图像和CSS。

我的web.config看起来像这样,但似乎没有帮助这些网址。因此它们都是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上的目录树是:

万维网

应用

根目录

php cakephp iis iis-7.5 cakephp-3.0
2个回答
0
投票

@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古怪的蛋糕不能正确检测基地本身:)”


0
投票

在根文件夹上创建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>
© www.soinside.com 2019 - 2024. All rights reserved.