简体   繁体   中英

Laravel routes are not working

I have this really weird issue where the routing process on Laravel seems to not work at all.. I get NotFoundHttpException every time I try to load another route except the default one( / )

These are my files:

routes.php

<?php

Route::get('/', function () {
    return view('welcome');
});

Route::get('/test', function () {
    return "WORKING?";
});

website apache config ( myquotes.conf located in /etc/apache2/sites-available )

<VirtualHost *:80>
    ServerName my.qoutes
    ServerAlias www.my.quotes
    ServerAdmin admin@my.quotes
    DocumentRoot /var/www/myquotes/public/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

hosts rule

127.0.0.1   my.quotes

And php artisan route:list returns this

+--------+----------+------+------+---------+------------+
| Domain | Method   | URI  | Name | Action  | Middleware |
+--------+----------+------+------+---------+------------+
|        | GET|HEAD | /    |      | Closure |            |
|        | GET|HEAD | test |      | Closure |            |
+--------+----------+------+------+---------+------------+

So I don't really understand where the problem is. If I try to load /test I get the error, if I edit the function form / , nothing happens in the browser, the same view with Laravel 5 on it is shown. I have some other websites in /var/www , are those the problem or influencing it? The routes from the other websites are not working either. What should I do?

EDIT: Tested in both Chromium and Firefox and the same
EDIT2: Okay.. After some more tweaking I found out that the problem was that I had 3 websites active under sites-enabled directory in /etc/apache2 and the webserver was using the first one's configuration file and not the one form myquotes . The question now is how to have multiple sites running on the same webserver?

To manage different sites on the same webserver, you will need to create different VirtualHosts to a different port or domain, for example, inside sites-enabled with a symlink to sites-available , you can have:

site1.conf
site2.conf
site3.conf

Each of them in a different port on the same webserver and they will be accessible. Make sure that the ports you're using are opened. You can add an alias to each of them to handle them differently.

See the documentation here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM