nginx - 将 2 个 url (%20) 重定向到 nginx 中的一个
问题描述
我有这个我无法解决的问题。我有一个 nginx 服务器,我必须进行这种类型的重定向。
http://midomain.com/xxxx/xxxx/ http://wikipedia.com/xx --> http://midomain.com/yyyy
由于我有两个带空格的网址,因此无法使其正常工作。
我尝试了多种方法。
rewrite ^/xxxx/xxxx/\ http://wikipedia.com/xx http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/\ http://wikipedia.com/xx" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/%20http://wikipedia.com/xx http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/%20http://wikipedia.com/xx" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/\ http://wikipedia.com/xx/$ http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/\ http://wikipedia.com/xx/$" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/%20http://wikipedia.com/xx/$ http://midomain.com/yyyy permanent;
我不知道我是否做错了什么。
解决方案
Nginx 在通过rewrite
. 被%20
解析为文字空格字符,连续/
字符被单个 . 替换/
。正是最后一点给你带来了问题。
例如:
rewrite "^/xxxx/xxxx/ http:/wikipedia\.com/xx$" http://midomain.com/yyyy permanent;
推荐阅读
- javascript - 具有反应状态的object.js(无法读取未定义的属性'map')
- html - Vue v-for 指令不呈现正确的 html
- cassandra - 如果在 Apache Cassandra 中,数据中心和机架不直接与物理机架或数据中心相关联,那么如何处理容错?
- laravel - Laravel 类型提示,模型保存时 id 返回 null
- arrays - C:减去数组
- hibernate - 在 Hibernete 多租户环境中,persist() 后无法获取实体 ID
- python - Pandas:将一行字符串分成 4 列;问题:列由逗号、制表符和空格分隔
- ios - Flutter iOS:无法检测到连接的iOS模拟器
- java - 尝试使用 OncePerRequestFilter 时出现 java.lang.NoSuchMethodException
- verilog - 我的 verilog 代码出现此错误,“Illegal operation for constant expression”