虚拟主机不适用于laravel 5.1

时间:2016-04-04 10:46:51

标签: laravel virtualhost

使用虚拟主机Laravel路由不能正常运行它可以访问public / index.php但是路由无效可以帮助我解决这个问题。

<VirtualHost *:80>
    ServerName laravel.dev
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mylaravel/public/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>

    <Directory /var/www/mylaravel/public/>
        Options +Indexes +FollowSymLinks +MultiViews
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

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

在此设置之后,而不是获取特定路由的结果,它显示404错误正常的php风格。

2 个答案:

答案 0 :(得分:0)

您应该将您的Web服务器(Apache)指向公共目录,但您不需要在URL和路由中使用publicindex.php

正确的路线是:

Route::get('foo/bar', function () {
    return 'Hello World';
});

Route::get('/', function () {
    return 'It's the index page!';
});

https://laravel.com/docs/5.1/routing#basic-routing

答案 1 :(得分:0)

对于禁用apache mod_rewite你遇到了这个问题。通过这种方式,我解决了我的问题

//keep this in /etc/apache2/sites-available/000-default.conf file
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

//enable mod rewrite
a2enmod rewrite

//restart apache
service apache2 restart

了解更多http://www.kingpabel.com/apache-mod-rewrite/