WordPress on Ubuntu – “File not Found” for home.php – Trying to Redirect to Root Folder

Question

I recently did a one-click installation on a Ubuntu server set up via Vultr. There is a PHP URL path (site.com/home.php) that I want to 301 redirect to the root folder (site.com/) but nothing has worked so far. Here are a few things I tried…

Set up .htacess file with mod rewrite rule (seems to ignore this)
Looked into nginx config files. I have three.
cockpit.conf
wordpress_http.conf
wordpress_https.conf
I tried updating a few things based on other threads but nothing worked (I’m a beginner with server configurations so I might have done the wrong thing too). The content of each config file is:

cockpit.conf

server {
    listen 9080 ssl;
    server_name _;
    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;
    access_log /var/log/nginx/cockpit_access.log combined;
    error_log /var/log/nginx/cockpit_error.log;
    server_tokens off;
    location / {
        # Required to proxy the connection to Cockpit
        proxy_pass https://127.0.0.1:9090;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        # Required for web sockets to function
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        # Pass ETag header from Cockpit to clients.
        # See: https://github.com/cockpit-project/cockpit/issues/5239
        gzip off;
    }
}

wordpress_http.conf

upstream php-handler-http {
server 127.0.0.1:9000;
}
server {
listen 80 default_server;
server_name _;
#server_name wordpress.example.com;

root /var/www/html/;
index index.php;

# set max upload size
client_max_body_size 2G;
fastcgi_buffers 64 4K;

access_log /var/log/nginx/wordpress_http_access.log combined;
error_log /var/log/nginx/wordpress_http_error.log;

server_tokens off;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
try_files $uri $uri/ /index.php?$args ;
}

# protected area (XHProf)
location ^~ /xhprof/xhprof_html/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd/xhprof;

location ~ .php(?:$|/) {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_FLAG "session.auto_start=off n mbstring.encoding_translation=off";
fastcgi_param PHP_VALUE "assert.active=0 n mbstring.http_input=pass n mbstring.http_output=pass";
fastcgi_pass php-handler-http ;
fastcgi_read_timeout 60s;
}
}

# protected area (phpmyadmin)
location ^~ /mysqladmin/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd/phpmyadmin;

location ~ .php(?:$|/) {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_FLAG "session.auto_start=off n mbstring.encoding_translation=off";
fastcgi_param PHP_VALUE "assert.active=0 n mbstring.http_input=pass n mbstring.http_output=pass";
fastcgi_pass php-handler-http ;
fastcgi_read_timeout 60s;
}
}

location ^~ /wp-admin/install.php {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd/wpadmin;

location ~* .(htaccess|htpasswd) {
deny all;
}

location ~ .php(?:$|/) {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
fastcgi_pass php-handler-http;
fastcgi_read_timeout 60s;
}
}

location ~* .(htaccess|htpasswd) {
deny all;
}

location ~* .(?:ini|conf|txt)$ {
deny all;
}

location ~ .php(?:$|/) {
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
fastcgi_pass php-handler-http;
fastcgi_read_timeout 60s;
}

# set long EXPIRES header on static assets
location ~* .(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
access_log off;
}

}

wordpress_https.conf

upstream php-handler-https {
    server 127.0.0.1:9000;
}

server {
    listen 443 ssl default_server;
    server_name _;
    #server_name wordpress.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    root /var/www/html/;
    index index.php;

    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;

    access_log /var/log/nginx/wordpress_https_access.log combined;
    error_log /var/log/nginx/wordpress_https_error.log;

    server_tokens off;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args ;
    }

    # protected area (XHProf)
    location ^~ /xhprof/xhprof_html/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/xhprof;

        location ~ .php(?:$|/) {
          fastcgi_split_path_info ^(.+.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param PHP_FLAG "session.auto_start=off n mbstring.encoding_translation=off";
          fastcgi_param PHP_VALUE "assert.active=0 n mbstring.http_input=pass n mbstring.http_output=pass";
          fastcgi_pass php-handler-http ;
          fastcgi_read_timeout 60s;
        }
    }

    # protected area (phpmyadmin)
    location ^~ /mysqladmin/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/phpmyadmin;

        location ~ .php(?:$|/) {
          fastcgi_split_path_info ^(.+.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param PHP_FLAG "session.auto_start=off n mbstring.encoding_translation=off";
          fastcgi_param PHP_VALUE "assert.active=0 n mbstring.http_input=pass n mbstring.http_output=pass";
          fastcgi_pass php-handler-http ;
          fastcgi_read_timeout 60s;
        }
    }

    location ^~ /wp-admin/install.php {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/wpadmin;

        location ~* .(htaccess|htpasswd) {
            deny all;
        }

        location ~ .php(?:$|/) {
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;
            fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
            fastcgi_pass php-handler-https;
            fastcgi_read_timeout 60s;
        }
    }

    location ~* .(htaccess|htpasswd) {
        deny all;
    }

    location ~* .(?:ini|conf|txt)$ {
        deny all;
    }

    location ~ .php(?:$|/) {
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
        fastcgi_pass php-handler-https;
        fastcgi_read_timeout 60s;
    }

    # set long EXPIRES header on static assets
    location ~* .(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
        expires 30d;
        access_log off;
    }

}


server {
    listen 443 ssl ;
    server_name www.gardenfreshsalsa.com gardenfreshsalsa.com; # managed by Certbot
    #server_name wordpress.example.com;
    ssl_certificate /etc/letsencrypt/live/gardenfreshsalsa.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/gardenfreshsalsa.com/privkey.pem; # managed by Certbot

    root /var/www/html/;
    index index.php;

    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;

    access_log /var/log/nginx/wordpress_https_access.log combined;
    error_log /var/log/nginx/wordpress_https_error.log;

    server_tokens off;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args ;
    }

    # protected area (XHProf)
    location ^~ /xhprof/xhprof_html/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/xhprof;

        location ~ .php(?:$|/) {
          fastcgi_split_path_info ^(.+.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param PHP_FLAG "session.auto_start=off n mbstring.encoding_translation=off";
          fastcgi_param PHP_VALUE "assert.active=0 n mbstring.http_input=pass n mbstring.http_output=pass";
          fastcgi_pass php-handler-http ;
          fastcgi_read_timeout 60s;
        }
    }

    # protected area (phpmyadmin)
    location ^~ /mysqladmin/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/phpmyadmin;

        location ~ .php(?:$|/) {
          fastcgi_split_path_info ^(.+.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param PHP_FLAG "session.auto_start=off n mbstring.encoding_translation=off";
          fastcgi_param PHP_VALUE "assert.active=0 n mbstring.http_input=pass n mbstring.http_output=pass";
          fastcgi_pass php-handler-http ;
          fastcgi_read_timeout 60s;
        }
    }

    location ^~ /wp-admin/install.php {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/wpadmin;

        location ~* .(htaccess|htpasswd) {
            deny all;
        }

        location ~ .php(?:$|/) {
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;
            fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
            fastcgi_pass php-handler-https;
            fastcgi_read_timeout 60s;
        }
    }

    location ~* .(htaccess|htpasswd) {
        deny all;
    }

    location ~* .(?:ini|conf|txt)$ {
        deny all;
    }

    location ~ .php(?:$|/) {
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
        fastcgi_pass php-handler-https;
        fastcgi_read_timeout 60s;
    }

    # set long EXPIRES header on static assets
    location ~* .(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
        expires 30d;
        access_log off;
    }
}

Would someone be able to point me in the right direction?

Desired Result

https://www.abcde.org/home.php -> 301 redirects https://www.abcde.org/

0
user3762448 5 months 2020-12-24T06:10:22-05:00 0 Answers 4 views 0

Leave an answer

Browse
Browse