CakePHP报500错误的解决方法

我把CakePHP做的网站传到主机上, 发现只有首页能打开. 点其他链接都报500错误. 在看不到日志的情况下问题出现的可能性是多种多样的.
后来google一下, 发现有人遇到过类似的问题, 解决方法是换个主机…….

不信邪. 首页能打开就说明我的配置没错, CakePHP是能正常运行的. 可能问题出现在URL的Rewrite上, 于是我尝试使用/index.php?url=service (注: service是controller的名字)来打开, 可以打开. 更加证实了CakePHP是没问题的想法. 于是我就修改了.htaccess.
原来内容是

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

我改成

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

看到吗? 我给index.php前面加了个斜线, 问题解决.
这会是一个很好的解决方法吗? 继续google, 后来在cakephp的官方网站上找到了一个方法.

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

参考: CakePHP: 500 Internal Error

Share
This entry was posted in 编程. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">