[英]Defining Document Root in Apache2/Cake PhP
我有一個破碎的Cake PHP網站,我沒有寫,但我負責修復。 我有主控制器,但沒有css / js /圖像,當我點擊鏈接時,我得到404未找到。 我相信mod_rewrite或apache中的docroot配置有些不對勁。
在閱讀Cake文檔時,我發現了這個:
“app / webroot在生產設置中,此文件夾應作為應用程序的文檔根目錄。此處的文件夾也可用作CSS樣式表,圖像和JavaScript文件的保留位置。”
在我的/ etc / apache2 / sites-enabled / this-site中,我看到了這個:
DocumentRoot /u02/data/docroots/this_site
<Directory /u02/data/docroots/this_site>
Options -Indexes
AllowOverride none
Order deny,allow
Allow from all
</Directory>
所以,我的問題:上面的配置塊是否需要:/ u02 / data / docroots / this_site / app / webroot作為DocumentRoot和?
您可以考慮在其他任何地方尋找故障排除嗎?
由於您可以編輯apache配置文件,因此最適合進行標准生產安裝。
以上配置塊是否需要:... / app / webroot作為DocumentRoot
假設路徑存在:是的。
這將修復損壞的css / js / images。
將重寫規則放在虛擬主機配置中:
DocumentRoot /u02/data/docroots/this_site/app/webroot
<Directory /u02/data/docroots/this_site/app/webroot>
Options -Indexes
AllowOverride none
Order deny,allow
Allow from all
// added
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
然后,這將把對非任何文件的任何請求路由到應用程序。
驗證所使用的重寫規則是否與正在使用的CakePHP版本兼容,以上是基於最新版本的規則 - 它多年來發生了變化 ,使用錯誤的重寫規則可能會產生意想不到的副作用。
AllowOverride none
這可以防止apache讀取.htaccess
文件。 如果您要將此更改為AllowOverride all
,並假設當前忽略的.htaccess
文件存在,則該站點將起作用 - 但作為開發安裝。
試試這個:
<VirtualHost *:80>
ServerAdmin xxxxxx@test.ro
ServerName test.ro
ServerAlias www.test.ro
DirectoryIndex index.php
DocumentRoot /u02/data/docroots/this_site
ErrorLog /u02/data/docroots/this_site/error.log
CustomLog /u02/data/docroots/this_site/access.log combined
<Directory "/u02/data/docroots/this_site">
Options -Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
你應該有3個.htaccess文件:
/u02/data/docroots/this_site/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
/u02/data/docroots/this_site/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/u02/data/docroots/this_site/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
希望這可以幫助 ;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.