[Solve] The requested URL was not found on this server after installing Magento 2

After installing Magento 2, you may face the problem “The requested URL was not found on this server“. You cannot access both backend and frontend of Magento 2 even it’s just a fresh installation.

The error looks like this

requested URL not found magento 2

What is the cause of this error?

The error occurs because of .htaccess file on your Magento 2 installation folder. Htaccess file is missing or wrong setting make Magento 2.

If you’re using Nginx, the rewrite part of Nginx conf file may be missing or not working.

Temporarily solution

You can gain access to website by putting “index.php” in the url like this example: yourwebsite.com/index.php or for admin access: /magento2/index.php/admin

Permanent fix

You need a proper .htacess file to make URL rewrite works.

You can download the file here

After downloading the file, rename it from .htaccess.sample to .htaccess and put into Magento root folder

In case the error is still there after putting new .htaccess file, you will have to check if rewrite module is enabled on your web server

For apache:

Change apache virtual host file (by default located in /etc/httpd/conf/httpd.conf) from:

<Directory /var/www/>

    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted

</Directory>

To

 <Directory /var/www/html>

           Options Indexes FollowSymLinks MultiViews

           AllowOverride All

           allow from all

</Directory>

This will enable mod_rewrite for apache

Now restart apache and the site should work normally

For nginx

Add these lines:

server {

   index index.php;

   if ($request_uri ~* "^(.*/)index\.php$") {

       return 301 $1;

   }

   location / {

       # ...

   }

}

After you’re done, restart Nginx to see if the error is fixed

Note: Nginx does not support .htaccess file, so you don’t need .htaccess file if you are using Nginx as your web server

Now your site should work properly

site working

Explanation

The following lines missing in .htaccess file may cause.

############################################

## never rewrite for existing files, directories and links

   RewriteCond %{REQUEST_FILENAME} !-f

   RewriteCond %{REQUEST_FILENAME} !-d

   RewriteCond %{REQUEST_FILENAME} !-l

############################################

## rewrite everything else to index.php

   RewriteRule .* index.php [L]

</IfModule>

RewriteRule .* index.php [L] rewrite all the URLs to url/index.php so that you can access all url without putting index.php

If you still face the error after trying all the solution above, drop your comment here and I will try my best to fix it for you.

The following two tabs change content below.