dongzouban9871 2011-10-30 14:42
浏览 101
已采纳

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

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>
  • 写回答

1条回答 默认 最新

  • douzhi3776 2011-10-31 15:45
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错