【发布时间】:2018-08-11 02:46:13
【问题描述】:
我正在尝试将 404 请求重定向到我们网站的主页,即 index.php。接收 404 错误消息的示例 URL 是此 URL https://www.website.com/directory/page。我尝试将以下行添加到我的配置文件中:error_page 404 /index.php;。当我这样做时,我不再收到关于 HTTPS 请求的 404。它显示了我希望的主页。但我仍然收到 HTTP 请求的 404 错误。关于如何让它在 HTTP 上也能正常工作的任何建议?
我目前正在运行 NGINX 服务器。这是我的配置文件的一部分:
server {
server_name acme.com;
return 301 $scheme://www.acme.com$request_uri;
}
server {
listen 80;
server_name www.acme.com;
#BEGIN SSL
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/acme.com.chained.crt;
ssl_certificate_key /etc/nginx/ssl/acme.com.key;
# Makes for the most secure connections
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
#END SSL
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ $uri.html $uri.php?$query_string;
}
error_page 404 /index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
【问题讨论】:
标签: php .htaccess nginx server