【问题标题】:Force Nginx to redirect plain domain to index.php?强制 Nginx 将普通域重定向到 index.php?
【发布时间】:2017-07-10 20:53:21
【问题描述】:

我目前正在使用 EasyEngine 在 Nginx 服务器上运行 IPS 社区套件论坛,并且我一直在尝试找到一种将 http://example.com/ 重定向到 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;
}

任何帮助将不胜感激!

【问题讨论】:

  • 你为什么要这样做?
  • ceejayoz,我一直遇到身份验证问题,当它位于example.com/index.php(或基本上是除example.com 之外的任何页面)时,一切正常。我只是认为这将是最简单的修复解决方案。
  • 这听起来像是你应该调查和修复的事情,而不是仅仅用一个 hacky 解决方法来修补它。

标签: php redirect nginx invision-power-board


【解决方案1】:

试试这个:

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

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

【讨论】:

    【解决方案2】:

    您可以使用完全匹配的location 块。请参阅this document 了解更多信息。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 1970-01-01
      • 2013-06-26
      相关资源
      最近更新 更多