zoukankan      html  css  js  c++  java
  • Laravel5 根目录router无效

    在安装好apache和Laravel后,在网站根目录/var/www/html下新建laravel工程命名为laravel。

    在浏览器输入localhost/laravel后发现显示的是网站的根目录结构。输入localhost/laravel/server.php后才显示出正确的欢迎界面。

    在laravel/app/Html/router.php里新注册一个router:

    Route::get('/test', function () {
        return 'asdf';
    });

    发现只有访问localhost/laravel/server.php/test才能有正确输出。

    百度后发现laravel的访问入口应该是根目录下的public。

    编辑apache的apache2.conf添加。(apache2.conf位于/etc/apache2/apache2.conf, /var/www/html/为站点目录)。

    <Directory /var/www/html/laravel/public>
        Options Indexes FollowSymLinks
        AllowOverride All 
        Require all granted
    </Directory>

    同理编辑/etc/apache2/sites-enable/000-default.conf:

    <VirtualHost *:80>
    
    ServerName localhost
    
    DocumentRoot "/var/www/html/laravel/public"
    
    <Directory "/var/www/html/laravel/public">
    
    Options Indexes FollowSymLinks Includes execCGI
    
    AllowOverride All
    
    Order Allow,Deny
    
    Allow From All
    
    </Directory>
    
    </VirtualHost>

    删除/var/www/html/index.html。重启apache2

    service apache2 restart

    打开浏览器,访问localhost,即可看见欢迎页面,访问localhost/test,路由也正常显示。

  • 相关阅读:
    跳台阶问题
    腾讯,百度,网易游戏,华为笔面经验
    进程、线程、应用程序之间的关系
    const用法小结
    vc快捷键
    文献阅读以及如何管理
    数据类型转换
    vc Debug Release
    如何阅读文献
    如何提高表达能力
  • 原文地址:https://www.cnblogs.com/xiaoxiaff/p/5268736.html
Copyright © 2011-2022 走看看