skip to Main Content

After I enabled NGINX from Plesk (Web Pro) all my posts in my main and sub-directory blogs give 404 Page Not Found error.

I placed the following code in my "Additional NGINX Directives" in Plesk to fix all the URLS, but it only fixed the main site (example.com) while the sub-directory blogs (example.com/tech/, example.com/mag/ and example.com/dispatch/) are still giving 404 error.

# WordPress Permalinks
if (!-e $request_filename) {
    rewrite ^(.+)$ /index.php?q=$1 last;
}

After that, I removed the code and placed the following one:

if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
}

I found this code in one of the official Plesk pages, and it says:

If a WordPress installation is located in a subdirectory (for example, "httpdocs/sub-dir") or this is a WordPress multisite network based on subdirectories, add the /sub-dir/ before /index.php?$1 so it will look like this: rewrite ^/(.*)$ /sub-dir/index.php?$1;
Note: For WordPress multisite network based on subfolder, add the above rule for each subdirectory.

As of now I got this (which doesn’t work):

if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
rewrite ^/(.*)$ /tech/index.php?$1;
rewrite ^/(.*)$ /mag/index.php?$1;
rewrite ^/(.*)$ /dispatch/index.php?$1;
}

Any help will be much appreciated!

P.S. The main website works like a charm. In example.com/tech/ and /mag/ and /dispatch/ while the homepages are fine, the posts are giving me a 404 page error.

2

Answers


  1. Chosen as BEST ANSWER

    So after a month of searching I finally found a solution that works great.

    First, login into your Plesk (used Plesk for this) and go to your website's "Apache & nginx Settings" page. In the "Additional NGINX Directives" (modify first) paste the following code:

    if (!-f $request_filename){
        set $rule_0 1$rule_0;
    }
    if (!-d $request_filename){
        set $rule_0 2$rule_0;
    }
    if ($rule_0 = "21"){
        rewrite ^/tech/(.*)$ /subfolder1/index.php?url=$1 last;
    }
    if (!-f $request_filename){
        set $rule_1 1$rule_1;
    }
    if (!-d $request_filename){
        set $rule_1 2$rule_1;
    }
    if ($rule_1 = "21"){
        rewrite ^/dispatch/(.*)$ /subfolder2/index.php?url=$1 last;
    }
    

    subfolder1 and subfolder2 stands for the website's root folder for every sub-directory site.

    • subfolder1 stands for example.com/subfolder1
    • subfolder2 stands for example.com/subfolder2

    etc..

    For every subfolder WP site you want to add, just place the following code and change the subfolder1 with your site's name.

     if (!-f $request_filename){
            set $rule_0 1$rule_0;
        }
        if (!-d $request_filename){
            set $rule_0 2$rule_0;
        }
        if ($rule_0 = "21"){
            rewrite ^/tech/(.*)$ /subfolder1/index.php?url=$1 last;
        }
    

    P.S. The converted code needs to be added to the "Additional NGINX Directives".


  2. Try creating a new file ‘.htaccess’ via File Manager or upload it to /httpdocs/ or where your files are stored.

    file contents:

    IndexIgnore * # prevent directory listing
    Order deny,allow
    Allow from *
    # ------------------------------------------ # Rewrite so that php extentions are not shown
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search