【发布时间】:2018-09-17 07:02:17
【问题描述】:
有没有办法可以用空格(或+)替换以$request_uri 返回的非字母数字字符?
我想要做的是将我的一个站点中的所有 404 重定向到它的搜索引擎,其中查询是请求的 uri。所以,我的 nginx.conf 中有一个块,其中包含:
error_page 404 = @notfound;
location @notfound {
return 301 $scheme://$host/?s=$request_uri;
}
虽然这确实有效,但它返回的 url 是实际的 uri 完整的 -_/ 字符导致搜索始终返回 0 个结果
例如...给出这个网址:https://example.com/my-articles,重定向结束为:https://example.com/?s=/my-articles
我想要(最终)这样结束:https://example.com/?s=my+articles(不过,开头的 + 也可以正常工作...https://example.com/?s=+my+articles
我需要在没有 LUA 或 Perl 模块的情况下执行此操作。那么,我该如何实现呢?
【问题讨论】:
-
你能提供一些其他的样本(网址)
-
边走边编……问题已经够详细了
标签: regex string nginx replace