Error The requested URL login was not found on this server Apache Ubuntu Server at mydomain com Port 80

0 votes

When I load pages that are not root, the page won't load without index.php before the route. The error I get: 

The requested URL /login was not found on this server. Apache/2.4.7 (Ubuntu) Server at mydomain.com Port 80

To start with I have a virtual host file containing:

//also tried adding DirectoryIndex here before <directory>
<directory /var/www/mydomain.com>
    DirectoryIndex index.php
    AllowOverride ALL
</directory>

and a .htacces in my public with :

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

When running the website localy with xampp everything works fine. For hours i'm trying now but I can't fix it or find any error (logs are empty) or any solutions that I haven't tried yet.

Nov 12, 2020 in Laravel by kartik
• 37,520 points
14,037 views

1 answer to this question.

0 votes

Hello @kartik,

 your directory path is wrong. You need /public on the end because Laravel treats that directory as the web root. Try this:

<directory /var/www/mydomain.com/public>
    DirectoryIndex index.php
    AllowOverride ALL
</directory>

But the better solution is to put the contents of the .htaccess file in your virtual host. Like this:

<VirtualHost *:80>
    DocumentRoot "/var/www/mydomain.com/public"
    ServerName mydomain.com
    ServerAlias *.mydomain.com

    <Directory "/var/www/mydomain.com/public">
        # Ignore the .htaccess file in this directory
        AllowOverride None

        # Make pretty URLs
        <IfModule mod_rewrite.c>
            <IfModule mod_negotiation.c>
                Options -MultiViews
            </IfModule>

            RewriteEngine On

            # Redirect Trailing Slashes...
            RewriteRule ^(.*)/$ /$1 [L,R=301]

            # Handle Front Controller...
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
        </IfModule>
    </Directory>
</VirtualHost>

Also, you should make sure your config file is loaded by running:

apache2ctl -t -D DUMP_VHOSTS

This will print a list of all the loaded vhosts. If yours isn't in that list then make sure it is enabled by running:

a2ensite [name_of_your_config_file]

Then restart apache with:

service apache2 reload

Hope it helps!!

answered Nov 12, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

+1 vote
1 answer

Error:Class '\App\User' not found in Laravel when changing the namespace in Laravel?

Hello @kartik Go to config/auth.php and change App\User:class ...READ MORE

answered Apr 3, 2020 in Laravel by Niroj
• 82,840 points
30,198 views
0 votes
1 answer

Error: Class 'TestCase' not found in D:\xampp\htdocs\laravel\app\tests\ExampleTest.php on line 3 ,

Hello @kartik, Run following command in your project's ...READ MORE

answered Sep 28, 2020 in Laravel by Niroj
• 82,840 points
2,273 views
0 votes
2 answers

Error:Class 'App\Http\Controllers\App\Model' not found?

Class ‘App\Http\Controllers\Auth’ Not Found in Class ‘App\Http\Controllers\Auth’ not ...READ MORE

answered Aug 6, 2020 in Laravel by pakainfo
17,637 views
0 votes
1 answer

Artisan migration error “Class 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver' not found”?

Hello @kartik, This message shows up if you ...READ MORE

answered Apr 6, 2020 in Laravel by Niroj
• 82,840 points
5,789 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,051 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,010 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,934 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,839 views
0 votes
1 answer

Error: Class 'SoapClient' not found in /home/user/mysite.com/path/to/file.php on line 16

Hello @kartik, find this line in php.ini : ;extension=soap then ...READ MORE

answered Oct 29, 2020 in Laravel by Niroj
• 82,840 points
3,394 views
0 votes
1 answer

Error: 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue?

Hii, I had same problem when responding on ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,840 points
53,471 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP