cakePHP - 404- page not found error, when deploying on a different machine

谁都会走 提交于 2019-12-05 08:14:46

Sounds like an issue with mod_rewrite not working on that machine. What happens when you try to run a default Cake install? Does it load the CSS and all?

Is there a .htaccess file in your app directory (and in your webroot directory)?

Do you have FollowSymLinks turned on in your Apache config files?

I had the same problem.

I solved it by creating an .htaccess in public_html folder, with the following content:

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

It works for me.

If the above solutions have no effect, make sure the apache rewrite module is enabled

On debian it is disabled by default

a2enmod rewrite
service apache2 restart

I had to modify my httpd.conf file (it's location varies on your Linux installation-- mine was at /etc/httpd/conf/httpd.conf) in two places to get this to work on CentOS.

In addition to the <Directory /var/www> as mentioned in the CakePHP docs, if you go a little further down you'll see <Directory "/var/www/html"> which does not allow rewriting.

Change AllowOverride None to AllowOverride All.

Be sure to reset apache using sudo /sbin/service httpd restart.

In my case I ran into the fact that all posts controller requests (/posts/*) were returning 404. Other controller pages were working fine.

Turns out it was because I had a posts.sql file floating around in my web root. As soon as I moved the file, everything worked. Even with the .sql extension, Cake's rewrite rules made the request map to a non-existent posts folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!