[英]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.