Problem Description
- When visiting your website, the homepage works great, but visiting sub-pages that use permalinks or SEO friendly URLs results in a 404 even though you know those pages exist.
- Under PHP Settings for any given domain in Plesk, you may have the "run PHP as" configuration set to an option that includes nginx.
WordPress and other applications like it require rewrite rules which allow the web server engine to interpret the readable URLs for all pages except the homepage and convert them to a request that ensures the correct page is shown. Without these rewrites, sub-pages return a 404.
Reason #1 (apache): In the event there is no nginx found in the PHP Run as type (#2 above), then the problem is that you're missing the .htaccess file that should contain directions to your web server on how to display those sub-pages for your website.
Reason #2 (nginx): When running PHP directly through nginx (bypassing apache), you gain slight performance advantages, but you lose the capability to read the rewrite rules in the .htaccess file. Most web applications like WordPress use the .htaccess file to configure everything from the basics of operating permalinks to the more advanced caching speed improvements, and so without it, all of that functionality stops working.
Problem Resolution
Solution for Reason #1:
- You can find the correct .htaccess file contents in the documentation for the web application that runs your site. For example, WordPress has the default .htaccess file contents in their Codex here. Once you have the correct .htaccess file contents, you can use the Plesk File Manager or FTP to create the file and insert the correct content. Be sure that you don't forget the dot character (.) at the start of the filename: .htaccess
Solutions for Reason #2:
- If you're using shared hosting or reseller hosting, then you do not have access to configure the raw nginx rules and so you must instead go to the PHP Settings for the domain in Plesk and configure it to run PHP as either Apache + PHP-FPM (if available, this is preferred) or Apache + FastCGI. By using apache to run PHP, you're ensuring that the .htaccess file rules are used and therefore that permalinks or SEO friendly URLs will work successfully.
- If you have admin access to Plesk (if you have your own VPS), then you can go to "Apache & Nginx settings" for the domain and specify the nginx rule equivalents of what's in the .htaccess file to resolve this. Anything that you see in the WordPress .htaccess file will need to be replicated in custom nginx rules. If you have our Hands-On Support for VPS, we have provided you with three config files that can be enabled (by uncommenting them) that will take care of this for you. Please read more on that here.