2015-06-05 32 views
0

我所有的網址,圖片和CSS或應用程序所呈現前置CakePHP的3.0 IIS的web.config

/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上我的目錄樹:

WWW

應用

根目錄

回答

0

@ADmad幫助我知道這一點。事實證明,這與IIS中的web.config無關。它也不是CakePHP 3.0特定的東西。根據CakePHP IRC,CakePHP 3.x和CakePHP 2.x路由完全相同。這僅僅是IIS PHP的怪癖。

的解決方法是在你的配置更新App.base/app.php

'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> 
+0

它的正常工作 – Anuj

+2

請不要發佈純代碼的答案。也添加一些描述 –