Prestashop: Resolving the 404 error in the back office

Prestashop: Resolving the 404 error in the back office

I recently had to install PrestaShop, and I encountered a rather surprising problem. When trying to navigate the back office, only the homepage worked. The other pages displayed a 404 error.

The problem originates in Symphony's URL rewriting system for the back office. A configuration change is required.

This solution will be useful if you host your Prestashop instance yourself, or if you manage the web server configuration yourself.
If this is not the case, you can contact your service provider, or send them the link to this troubleshooting procedure.

The next steps depend on whether your web server is running on Apache or Nginx.

My web server runs on Apache.

If your server is running on Apache, first check that the URL rewriting module is enabled. It can be enabled with the following command:

sudo a2enmod rewrite

Once done, if the output indicates that the module has been activated, you can reload the Apache configuration with the following command:

sudo systemctl reload apache2

The rest of the procedure is located in the vhost file of the site served by the server. A template can be found here: https://devdocs.prestashop-project.org/9/basics/installation/advanced/httpd/

Once the configuration has been imported according to your server, simply activate the virtual host (if it isn't already enabled) and restart the Apache server. The problems should be resolved.

sudo systemctl a2ensite votresite.conf
sudo systemctl reload apache2

My web server runs on Nginx.

If your server is running on Nginx, there is no module to activate. However, the virtual host configuration will need to be adapted for the back office.

The sample configuration can be found here: https://devdocs.prestashop-project.org/9/basics/installation/advanced/nginx/

In this configuration (aside from configuring the certificate and ServerName), it is necessary to define the URL rewriting for the back office. Therefore, in the following block:

location /admin-dev/ {
        try_files $uri $uri/ /admin-dev/index.php$is_args$args;
    }

You will need to replace admin-dev with the exact name of the admin folder in the back office

This data is randomly named once the installation is complete.
You will need to go to the root of the Prestashop web folder to find the folder name.
In all cases, this folder will start with "admin-"

Thus, if the folder is named admin-jfddjj34743983jd, the directive will be entered as follows:

location /admin-jfddjj34743983jd/ { try_files $uri $uri/ /admin-jfddjj34743983jd/index.php$is_args$args; }
Each Prestashop installation uniquely renames this folder.
Therefore, it is absolutely necessary to refer to what exists on the web server.

Once done, activate (if it is not already activated) the vhost:

sudo ln -s /etc/nginx/site-available/votresite /etc/nginx/site-enable/
Replace yoursite with the number from your configuration file.

Finally, restart the Nginx service for the configuration to take effect.

sudo systemctl restart nginx