目前每个无效页面都是 500(内部服务器错误),因为我可能搞砸了我的服务器块配置。
不久前,我决定关闭我的网站,并创建了一个简单的单页,感谢您的主页。然而,旧链接和外部站点仍在尝试访问该站点的其他部分,这些部分不再存在。
如何强制将所有非主页(任何无效 URL)重定向到主页?
我尝试了以下块,但没有奏效:
location / {
try_files $uri $uri/ $document_uri/index.html;
}
我当前的配置是(我现在什至不提供 PHP 文件,即主页是简单的 html):
server {
server_name www.example.com example.com;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
root /srv/www/example.com/public_html;
index index.php index.html;
location / {
try_files $uri $uri/ $document_uri/index.html;
}
# Disable favicon.ico logging
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Allow robots and disable logging
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Enable permalink structures
if (!-e $request_filename) {
rewrite . /index.php last;
}
# Handle php requests
location ~ \.php$ {
try_files $uri = 404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_send_timeout 900;
fastcgi_read_timeout 900;
fastcgi_connect_timeout 900;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Disable static content logging and set cache time to max
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires max;
}
# Deny access to htaccess and htpasswd files
location ~ /\.ht {
deny all;
}
# Deny access to hidden files (beginning with a period)
location ~ /\. {
access_log off; log_not_found off; deny all;
}
}