【问题标题】:Wordpress on Ubuntu - "File not Found" for home.php - Trying to Redirect to Root FolderUbuntu 上的 Wordpress - home.php 的“找不到文件” - 尝试重定向到根文件夹
【发布时间】:2021-04-02 03:11:51
【问题描述】:

我最近在通过 Vultr 设置的 Ubuntu 服务器上进行了一键式安装。有一个 PHP URL 路径(site.com/home.php)我想 301 重定向到根文件夹(site.com/),但到目前为止还没有工作。以下是我尝试过的一些事情...

  1. 使用 mod 重写规则设置 .htacess 文件(似乎忽略了这一点)
  2. 查看了 nginx 配置文件。我有三个。
cockpit.conf
wordpress_http.conf
wordpress_https.conf

我尝试根据其他线程更新一些东西,但没有任何效果(我是服务器配置的初学者,所以我也可能做错了)。 每个配置文件的内容是:

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;
    }
}

有人能指出我正确的方向吗?

期望的结果

https://www.abcde.org/home.php -> 301 重定向 https://www.abcde.org/

【问题讨论】:

标签: php wordpress apache .htaccess nginx


【解决方案1】:

您的 .htaccess 是否位于 ...site/public 并具有适当的权限? 在你的 htaccess 中试试这个:

 # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^home\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /home.php [L]
</IfModule>
# END WordPress

【讨论】:

  • 感谢您的建议,但似乎不起作用。我将 .htaccess 文件放在 var/www/html/ 中,权限级别为 644,但 /home.php 仍然出现“找不到文件”错误。
猜你喜欢
  • 1970-01-01
  • 2015-10-06
  • 2018-10-17
  • 2017-04-09
  • 2011-09-17
  • 2011-12-20
  • 1970-01-01
  • 2020-03-13
  • 1970-01-01
相关资源
最近更新 更多