CakePHP 2.0 默认页面没有布局并显示 mod_rewrite 错误

发布于 2024-12-12 17:27:07 字数 1833 浏览 0 评论 0原文

我刚刚在我的服务器上配置了 cakePHP 2.0,但默认页面没有应用布局和 css。它还显示以下错误。

您的服务器上的 URL 重写配置不正确。 1) 帮我配置它 2) 我不/不能使用 URL 重写

我已经发现 no-layout/css 问题可能与 URL 重写错误有关,所以我按照 这个食谱页面但它没有任何效果。 URL 重写错误仍然可见,默认页面仍然缺少其布局和 CSS 样式。

一些信息

  • php.ini 中的显示错误已打开
  • html 头中包含的 css 和 favicon.ico 给出 404
  • 两个文件都在 webroot 文件夹中
  • webroot 文件夹的位置是 /admin/app/webroot/
  • phpinfo() 表示 mod_rewrite 模块已加载
  • 文件夹结构如下:
    • html(apache 根文件夹)
      • 管理员
        • 应用程序
          • ...
          • 网络根目录
            • CSS
              • cake.generic.css
          • ...
        • 蛋糕
        • ...
The error log only shows

[error] [client 212.***.***.***] File does not exist: /var/www/html/admin/css, referer: http://***.nl/admin/
[error] [client 212.***.***.***] File does not exist: /var/www/html/admin/img, referer: http://***.nl/admin/ 
[error] [client 212.***.***.***] File does not exist: /var/www/html/admin/favicon.ico

/admin/app/webroot/.htaccess 的内容

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /admin/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

/admin/app/.htaccess 的内容

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /admin/
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

I just configured cakePHP 2.0 on my server but the default page has no layout and css applied. It also displays the following error.

URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting

I already found out that the no-layout/css issue is probably related to the URL Rewriting error so I followed the steps described at this Cookbook page but it does not have any effect. The URL rewrite error is still visible and the default page still misses its layout and css styles.

Some info

  • Display errors in php.ini is on
  • The css and favicon.ico included in the html head give an 404
  • Both files are in webroot folder
  • Location of webroot folder is /admin/app/webroot/
  • phpinfo() says mod_rewrite module is loaded
  • Folder structure is as follows:
    • html (apache root folder)
      • admin
        • app
          • ...
          • webroot
            • css
              • cake.generic.css
          • ...
        • cake
        • lib
        • ...

The error log only shows

[error] [client 212.***.***.***] File does not exist: /var/www/html/admin/css, referer: http://***.nl/admin/
[error] [client 212.***.***.***] File does not exist: /var/www/html/admin/img, referer: http://***.nl/admin/ 
[error] [client 212.***.***.***] File does not exist: /var/www/html/admin/favicon.ico

Contents of /admin/app/webroot/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /admin/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Contents of /admin/app/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /admin/
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老娘不死你永远是小三 2024-12-19 17:27:07

我最初将此作为评论发布,但由于这似乎与OP相关,我将其作为正式答案。样式表链接给出 404 错误。

没有布局,你的意思是没有 HTML? cake.generic.css 文件是否正确加载?如果模块正确加载,mod_rewrite 消息的 div 会被默认 CSS 隐藏,但如果未包含 CSS,您仍然可能会看到它。

我在 1.3 安装时遇到过这个问题,所以我不确定它是否适用于 2.0。

至于 404 错误,这可能是一个多余的问题:但是 favicon.ico 实际上存在于 webroot 目录中,并且 cake.generic.css 存在于 中/webroot/css/

另外,您是否在子目录中运行应用程序,或者是 Web 服务器的 HTTP 根目录中的 app 目录?

如果您在子目录中运行应用程序,您可能需要更改模型、控制器所在的 app 目录(或任何名称)的 .htaccess 中的 RewriteBase等存储在 webroot 目录中。

/app 目录的 .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /YOUR_APP_DIR/
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
 </IfModule>

/app/webroot

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /YOUR_APP_DIR/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

将 YOUR_APP_DIR 更改为网络服务器上的相关路径。 这里有更多 对于 Cake 的特定安装,它可能适用于您的设置。

编辑:
.htaccess 看起来不正确。我认为这两个文件中应该是: /admin/app/

如果这不起作用,您可以研究在 default.ctp 中调用 CSS 的方式。对 CSS 的调用的格式类似于 default.ctp 中的格式:
Html->css(array("/css/cake.generic"), "stylesheet", array("media"=>"screen")); ?>

您还可以通过在 /View/Layouts 中放置具有该名称的文件来覆盖库存 default.ctp,Cookbook 示例可以在 /View/Layouts 中找到 < a href="http://book.cakephp.org/view/1080/Layouts" rel="nofollow">此处。完成后,您可以尝试 css 文件的完整路径,看看服务器是否正确提供服务。

I originally posted this as a comment, but as this seems to be of relevance to the OP I'll make it an official answer. The stylesheet link gives a 404 error.

By no layout, you mean no HTML? Is the cake.generic.css file properly loaded? The div of the mod_rewrite message is hidden by the default CSS if the module is properly loaded, but if the CSS is not included you might see it anyway.

I've had this problem on 1.3 installations, so I'm not sure if it applies to 2.0.

As for the 404 error, it might be a superfluous question: but is the favicon.ico actually present in the webroot directory and the cake.generic.css in /webroot/css/?

Also, are you running the application in a subdirectory, or is the app directory in the HTTP root of the webserver?

If you are running the application in a subdirectory you might want to change the RewriteBase in both the .htaccess of the app directory (or whatever it's called) where your models, controllers, etc. are stored and the webroot directory.

The .htaccess for the /app directory:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /YOUR_APP_DIR/
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
 </IfModule>

And /app/webroot:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /YOUR_APP_DIR/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Change YOUR_APP_DIR to the relevant path on you webserver. Here's more on specific installations of Cake, it might be applicable to your setup.

EDIT:
The .htaccess doesn't look right. I think it should be: /admin/app/ in both files.

If that doesn't work you could investigate the way the CSS is called in default.ctp. The call to the CSS is formatted like so in default.ctp:
<?php echo $this->Html->css(array("/css/cake.generic"), "stylesheet", array("media"=>"screen")); ?>

You could also override the stock default.ctp by placing a file with that name in /View/Layouts, the Cookbook example can be found here. When that is done you can experiment with the full path to the css file and see if the server is correctly serving it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文