Laravel 5.1 routing not working except '/'

倾然丶 夕夏残阳落幕 提交于 2019-12-10 15:59:53

问题


I have created a new laravel project in /var/www/polyforms.me and created virtual host file 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

When I go to polyforms.dev it opens home page as it should, but when I go to let's say polyforms.dev/about it shows me this:

If I use php artisan serve and use http://localhost:8000/about everything works fine... What is the problem and how to solve it?


回答1:


I guess .htaccess is ignored. 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>



回答2:


Do you have a .htaccess file in the web root that points everything to index.php? If not, that's the problem (see the 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 for more information. It also may be the case that mod_rewrite is not enabled. If using Ubuntu, Debian or other Debian-based OS is used a sudo a2enmod rewrite followed by sudo service apache2 reload will suffice.




回答3:


You have .htaccess file in your public folder. So copy that into cpanel's root .htaccess file.



来源:https://stackoverflow.com/questions/32617251/laravel-5-1-routing-not-working-except

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