Laravel 5.1 路由不工作,除了“/”

Laravel 5.1 routing not working except '/'

我在 /var/www/polyforms.me 中创建了一个新的 laravel 项目并创建了虚拟主机文件 polyforms.conf:

<VirtualHost *:80>
    ServerName polyforms.dev

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/polyforms.me/public

    ErrorLog ${APACHE_LOG_DIR}/polyforms.me-error.log
    CustomLog ${APACHE_LOG_DIR}/polyforms.me-access.log combined
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

当我转到 polyforms.dev 时,它会正常打开主页,但是当我转到 polyforms.dev/about 时,它会显示以下内容:

如果我使用 php artisan serve 并使用 http://localhost:8000/about 一切正常...问题是什么以及如何解决?

我猜 .htaccess 被忽略了。 http://httpd.apache.org/docs/2.2/en/mod/core.html#allowoverride

<VirtualHost *:80>
    ServerName polyforms.dev

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/polyforms.me/public

    <Directory "/var/www/polyforms.me/public">
      AllowOverride all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/polyforms.me-error.log
    CustomLog ${APACHE_LOG_DIR}/polyforms.me-access.log combined
</VirtualHost>

您的网站根目录中是否有 .htaccess 文件将所有内容指向 index.php?如果没有,那就是问题所在(请参阅 Laravel docs on what to add where). If so, Apache may be configured to deny .htaccess overrides. In that case you'll need to add a segment in your VirtualHost configuration allowing those. See the Apache documentation 了解更多信息。也可能是 mod_rewrite 未启用的情况。如果使用 Ubuntu、Debian 或其他基于 Debian 的 OS 使用 sudo a2enmod rewrite 后跟 sudo service apache2 reload 就足够了。

您的 public 文件夹中有 .htaccess 文件。所以将其复制到 cpanel 的根 .htaccess 文件中。