gpt4 book ai didi

Nginx 重定向规则没有影响

转载 作者:行者123 更新时间:2023-12-04 15:29:09 25 4
gpt4 key购买 nike

尝试做一个简单的重定向:

rewrite https://url.example.com(.*) https://example.com/plugins/url permanent;

随时 url.example.com被击中,我希望它重定向到该特定路径。

编辑:

将尝试更好地解释这一点,因为我正在尝试从另一个域重定向到特定域。
server {
server_name example.com plugin.example.com;
root /home/www/example.com/public;
}

我看到了 location用于重定向,例如:
location / {
try_files $uri $uri/ /index.php?$query_string;
}

但不确定如何在我的情况下使用它,即更改 plugin.example.comexample.com/plugin .

例如:
http://plugin.example.com
https://plugin.example.com
https://plugin.example.com/blah
https://plugin.example.com/blah/more

所有这些都应该重定向到:
https://example.com/plugin

最佳答案

如果原始 URL 是 https://url.example.comhttps://url.example.com/然后是 rewrite 使用的规范化 URI和 location指令将是 / .方案、主机名和查询字符串都已被删除。

要永久重定向到具有不同主机名的 URL:

使用 rewrite (详见 this document):

rewrite ^/$ https://example.com/foo permanent;

或使用 locationreturn (详见 this document):
location = / {
return 301 https://example.com/foo;
}

第二种解决方案更有效,因为没有要处理的正则表达式。

如果原始 URL 包含查询字符串: rewrite除非尾随 ?,否则将自动附加它被添加。 return不会,但可以通过附加 $is_args$args 添加.

如果方案和主机名不变,那么这两个语句都可以简化:
rewrite ^/$ /foo permanent;

或者:
location = / {
return 301 /foo;
}

关于Nginx 重定向规则没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56503521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com