0
votes

[NOTE] - This issue was found to be due to incorrect Apache configuration. I have posted an answer which explains what I did wrong. I hope this helps!


I'm starting a project with Laravel and I've begun with creating the general routes. I want to create a request structure so that URLs of example.com go to organic routes, admin.example.com go to the admin dashboard of my app, and {workspace}.example.com goes to a dynamic route for my users' personal workspaces.

Currently I have the following routing structure:

Route::group(array('domain' => 'admin.example.com'), function() {

    Route::get('/', function() {
        echo 'This route works fine';
    });

    Route::get('/test', function() {
        // This route doesn't work...
        echo 'Test';
    });

});


Route::group(array('domain' => '{workspace}.example.com'), function() {

    Route::get('/', function() {
        echo 'This route works fine';
    });

    Route::get('/test', function() {
        // This route doesn't work...
        echo 'Test';
    });

});


Route::group(array('domain' => 'example.com'), function() {

    Route::get('/', function() {
        echo 'This route works fine';
    });

    Route::get('/test', function() {
        // This route doesn't work...
        echo 'Test';
    });

});

As you see, I have three routing groups. The first is for the admin prefixed URLs (to ensure that admin.example.com is not mistaken for a workspace prefix). There is the workspace prefix, and then finally the no-prefix route group.

As indicated in the code, all Route::get('/', ... routes work fine, however anything that is not the root does not work. I am receiving 404 errors when trying to go to example.com/test (and all the other domain prefixes).

What can I do to my routing to fix this and get the routes Route::get('/test', ... to work rather than just the / routes?

Much appreciated!

1
If you get rid of all your route groups and just have simple, group-less Route::get('/') and Route::get('/test'), does the /test route work? I have a sneaking suspicion this has nothing to do with groups/subdomains and everything to do with your webserver/.htaccess config.ceejayoz
@ceejayoz - Thank you for your response! I have just tested this and it turns out that it doesn't work! I had used basic routes before and it worked just fine. Obviously some config has been changed which is causing the issue. Any ideas of what could do this? ThanksRyan
@ceejayoz - I'm just being stupid! I changed my DocumentRoot to the Laravel project and in turn didn't set AllowOverride to All in the apache conf. Thanks for pointing this out!Ryan
That'll do it! Glad I could help you get to the cause. :-)ceejayoz

1 Answers

0
votes

This issue was being caused by the Apache configuration being incorrect rather than the routing being incorrect.

To avoid having issues like this in future, ensure that AllowOverride is set to All in your project's <Directory /var/www/myProject/public> block the apache.conf file like below:

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