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

时间:2017-07-10 20:53:21

标签: php redirect nginx invision-power-board

我目前正在使用EasyEngine在Nginx服务器上运行IPS社区套件论坛,我一直在尝试找到一种方法将http://example.com/重定向到http://example.com/index.php(仅当它仅仅是here时域)。这是我当前服务器的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;
}

任何帮助都会受到赞赏!

2 个答案:

答案 0 :(得分:1)

试试这个:

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

您可以在包含其他文件之前添加此内容。

答案 1 :(得分:1)

您可以使用完全匹配location块。有关详情,请参阅this document

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