【发布时间】:2012-10-20 02:37:54
【问题描述】:
当相关 URL 带有圆括号时,我很难在 nginx 中进行基本的 301 重定向。
通常,我会简单地使用这种类型的基本定位规则(不带括号):
location /abc/def {
rewrite /abc/def http://new.domain.com/abc/def/ permanent;
}
在上面提到的 URL 有圆括号的情况下:
来源网址:domain1.com/abc/def(ghi) 目标网址:domain2.com/abc/defghi
location /abc/def(ghi) {
rewrite /abc/def(ghi) http://new.domain2.com/abc/defghi permanent;
}
不幸的是,它不像第一个示例那么简单。从那以后,我已经多次更改规则以包括转义、用于打开和关闭圆括号的 urlencoded、正则表达式以允许在括号中捕获单个字符,但似乎没有任何效果。
转义方式:
location /abc/def\(ghi\)
当 URL 有括号时,如何获得 301 重定向以在 nginx 中工作?
【问题讨论】: