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 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用