强制 Nginx 将纯域重定向到 index.php?

Force Nginx to redirect plain domain to index.php?

我目前 运行 是一个使用 EasyEngine 的 Nginx 服务器上的 IPS Community Suite 论坛,我一直在尝试找到一种重定向 http://example.com/ to http://example.com/index.php 的方法(仅当它只是域时)。这是我当前的服务器 Nginx 配置:

server {
listen 80;
listen 443;
ssl on;
ssl_certificate /var/www/example.com/cert.pem;
ssl_certificate_key /var/www/example.com/key.key;

server_name example.com www.example.com;
access_log /var/log/nginx/example.com.access.log rt_cache;
error_log /var/log/nginx/example.com.error.log;


root /var/www/example.com/htdocs;

index index.php index.html index.htm;

include common/wpfc.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/classicaddons.com/conf/nginx/*.conf;
}

如有任何帮助,我们将不胜感激!

试试这个:

if ($request_uri = "/") {
    return 301 "/index.php";
}

您可以在包含其他文件之前添加它。

您可以使用完全匹配 location 块。有关更多信息,请参阅 this document

location = / {
    return 301 /index.php;
}